[Top][All Lists]

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

Re: I am trying to get pyeval to work.

From: Doug Stewart
Subject: Re: I am trying to get pyeval to work.
Date: Tue, 28 May 2019 13:59:48 -0400

On Tue, May 28, 2019 at 1:50 PM Mike Miller <address@hidden> wrote:
On Tue, May 28, 2019 at 08:02:41 -0400, Doug Stewart wrote:
>  On the IRC a person asked if we could send an email from inside of octave.
> Matlab has a function sendmail.
> So I thought about doing it from python. this next code works in python and
> you can do:
> system('python')  and this works from inside octave
> Then I tried to use pyexec  and do it from inside of octave.
> This is how far I have gotten  --  I cant get the last 3 lines of
> to work.
> any help would be good.

Of course, attached is a straightforward translation of the original. As
you can see it only requires very minimal changes from the original

1. Numbers are doubles by default in Octave as we all know, so you have
   to force the port to be a Python integer. Casting to an Octave int
   type will also work.

2. Octave doesn't have a syntax for multi-line strings like Python does,
   so I wrote the small example message body here with newline esacpes.
   For a longer multi-line string, one could use a cell array and the
   strjoin function.

3. The Python `with` statement is syntactic sugar, Octave doesn't have a
   syntax for declaring a local variable that will be destroyed
   automatically after a block scope is finished.

4. The `pyargs` function is required for passing keyword arguments to a
   Python function in the form that it expects.

That's it, attached example works for me with a suitable server, sender,
recipient, and password filled in.

Thank you for bringing this to my attention, I would like to include a
version of this script as an example in the package. Do you have an
original citation for the Python script? URL, author, license?

Keep the questions and examples coming!

when I try your code in octave 5.1.1
I get
error: 'py' undefined near line 1 column 8
error: called from
    email2 at line 1 column 6

DASCertificate for 206392

reply via email to

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