Ideas to optimize this getitem/eval call?
mario
mario.ruggier at gmail.com
Sat Jan 3 07:19:42 EST 2009
correction: the code posted in previous message should have been:
def __getitem__(self, expr):
try:
return eval(self.codes[expr], self.globals, self.locals)
except:
# We want to catch **all** evaluation errors!
# KeyError, NameError, AttributeError, SyntaxError, V
# alueError, TypeError, IOError, ...
#
# Special case:
# if KeyError is coming from self.codes[expr] lookup,
# then we add the compiledentry and try again:
if not expr in self.codes:
self.codes[expr] = compile(expr, '<string>', 'eval')
return self[expr]
# handle any other error...
More information about the Python-list
mailing list