self
holger krekel
pyth at devel.trillke.net
Fri Jun 7 11:33:55 EDT 2002
Vojin Jovanovic wrote:
> > Why such a
> > harsh reaction without bothering to correct the obvious 'typo'?
>
> No, it is not the 'typo'. I corrected that immediately.
ok. sorry for wrong accusations...
> However, all that aside, the problems is that your code just din't work
> after I corrected those 2 'typos'. Take a look yourself ....
>
> Python 2.1.2 (#31, Jan 15 2002, 17:28:11) [MSC 32 bit (Intel)] on win32
hmmm. it seems to be a problem with the python version: 'type(value)!=str'
comparison doesn't seem to work with python2.1 (works with 2.2).
So here goes my python2.1/2.2 version:
Python 2.1.3 (#1, Apr 20 2002, 10:14:34)
[GCC 2.95.4 20011002 (Debian prerelease)] on linux2
Type "copyright", "credits" or "license" for more information.
Welcome to Lazy Python. Type "help LazyPython" for help.
>>> class Evaluator:
def __init__(self, eqs={}):
self.__dict__['equations']=eqs
def __getattr__(self, name):
value = self.equations[name]
if type(value)!=type(''):
return value
scope={}
while 1:
try:
return eval(value, scope)
except NameError, n:
var=str(n).split("'")[1]
scope[var]=getattr(self, var)
def __setattr__(self, name, value):
self.equations[name]=value
>>> class Berta:
a=5
>>> e=Evaluator({'a':3})
>>> e.berta=Berta()
>>> e.g='berta.a*a'
>>> e.g
15
>>>
now i hope we are getting close to discussing the idea, finally :-)
regards,
holger
More information about the Python-list
mailing list