help-octave
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: I am trying to get pyeval to work.


From: Mike Miller
Subject: Re: I am trying to get pyeval to work.
Date: Mon, 27 May 2019 22:26:16 -0700
User-agent: Mutt/1.10.1 (2018-07-13)

On Tue, May 28, 2019 at 00:21:02 -0400, Doug Stewart wrote:
> I am trying to do
> python_cmd('import  smtplib,  ssl')
> and then latter do:
> 
> python_cmd('context = ssl.create_default_context()')
> but it says that there is no ssl
> 
> error: Python exception: NameError: name 'ssl' is not defined
>     occurred at line 1 of the Python code block:
>     context = ssl.create_default_context()
> error: called from
>     python_cmd at line 179 column 7
>     pythcmds at line 11 column 1
> 
> when I do it in python it all works. I was just trying to get it to work
> from octave.
> I tried
> pyexec('import  smtplib,  ssl')
> and this does not work.

The preferred and simplest way to do this would be

    context = py.ssl.create_default_context()

To summarize, there is no need to import anything, just call the fully
qualified py.library.function name.

Btw, the `python_cmd` function is part of the Symbolic package and is
completely unrelated to the Pythonic package (for now).

If you _really_ want to use pyeval and pyexec, this also works

    pyexec('import ssl')
    pyexec('context = ssl.create_default_context()')

or this

    pyexec('import ssl')
    context = pyeval('ssl.create_default_context()')

But I would much prefer people use the fully transparent and Matlab
compatible syntax `context = py.ssl.create_default_context()`.

HTH,

-- 
mike

Attachment: signature.asc
Description: PGP signature


reply via email to

[Prev in Thread] Current Thread [Next in Thread]