self

Terry Reedy tjreedy at udel.edu
Tue Jun 4 15:22:18 EDT 2002


"Vojin Jovanovic" <vjovanov at stevens-tech.edu> wrote in message
news:TL7L8.79$4p7.4100181 at newnews.cc.stevens-tech.edu...
[snip]
> Why is this all relevant? Well, I am working on embedding an
interpreted
> language in a large engineering application and Python is  one of
few
> candidates.  So I have been looking for its pros and cons.  So far
it passed
> all the tests except the above.  Because, imagine if we required
from the
> user of our system that he needs to type self. or even s. in front
of every
> new variable that he has in his equation, it would be a big turn
off.

Now that you have explained your actual problem, I believe there is a
simple solution that does not require breaking half of all Python code
written.

Add another dict 'Symbols' to your class.  Then eval/exec your
equations 'in' Symbols as the local/global namespace.  No 'self.'
needed then.  This is also a good idea for security reasons, but
others have posted on that.   Plus, you can initialize 'Symbols' with
the contents of the math module and add any other engineering
functions you want available for use in equations.

Terry J. Reedy





More information about the Python-list mailing list