eval, exec and execfile dilemma
Steven D'Aprano
steve+comp.lang.python at pearwood.info
Sat Jul 30 19:31:21 EDT 2011
Laszlo Nagy wrote:
> 100 functions/second
> installed to global namespace doesn't sound well.
What on earth are you doing needing to use exec to create hundreds of
functions??????
Have you considered not using exec at all, and using a good old-fashioned
factory function and closures?
def factory(x):
def inner(param):
return param + x
return inner
plusone = factory(1)
plustwo = factory(2)
I'm betting that this will be much faster than exec, and much more readable.
--
Steven
More information about the Python-list
mailing list