|
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 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 email1a.py') and this works from inside octave
> https://www.dropbox.com/s/35in67pc6lajyne/email1a.py?dl=0
>
> 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
> email1a.py 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
Python.
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!
--
mike
[Prev in Thread] | Current Thread | [Next in Thread] |