self

Sean 'Shaleh' Perry shalehperry at attbi.com
Tue Jun 4 14:49:04 EDT 2002


> As you can see, equations get added on the fly and the parsing gets done as
> the attribute is being called.  Now, notice that ugly self. thing in the
> equations.  Instead of just typing >>>A.f='a*c' I have to add self in front
> a and c to achieve the desired effect.  I could not find any other way to
> implement the class in order to avoid typing self. which of course it
> doesn't mean that there isn't any. If anybody has an idea how to do this
> please let me know.  Otherwise, here is the situation where the self
> concept is bad and having such a dynamic language like Python I think there
> has to be a way out of this problem.
> 
> 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.
> 

why can't your class be an interpreter for math expressions?

it sees 'a*c' and asks it own dict 'do we know a?' if so it access dict['a']
and returns its value.  Looking at your example you seem to be implementing a
symbolic calculator.  Most implementations I have seen involve writing a small
language with interpreter.





More information about the Python-list mailing list