self

holger krekel pyth at devel.trillke.net
Wed Jun 5 11:48:14 EDT 2002


Nicola Kluge wrote:
> This is an interesting idea.  However, your approach doesn't handle the dot
> notation.
> For example,
> If object.x was = to 3 and g was = to 4 I need  that
> e.f='object.x*g' gives 12.
> Just having e=Evaluator({'a':'3', 'b':'a*17', 'c':
> 'b*a','object.x':'3','g':'4'})
> doesn't work.  While parsing, 'object.x' is not taken as one symbol in your
> approach.
> I need to have object capabilities in the equations.

i think i have to dig deeper into the python sources to see how 
and if your task could be done cleanly. One of the main problems seems
to be that you can't pass your own 'dictish' object to 'eval' or 'exec'.
(Actually you can, but the interception points like '__getattr__' 
don't get called. smells like a bug to me though this might be arguable).

And yes, i think that having an explicit 'self' is a very good pythonic idea (tm).
i know because i have done some pretty weird stuff like transfering 'locals()'
into the self-dict and back but it often isn't worse it. 

have fun,

    holger





More information about the Python-list mailing list