[Python-Dev] lazy evaluation redux

Guido van Rossum guido@python.org
Tue, 11 Feb 2003 10:35:32 -0500


Sorry, this thread doesn't belong on python-dev.  If you really need
lazy evaluation, you can do it without changes to the langage.  Just
enclose lazy arguments in quotes.  Then you can use something like
this:

import sys

def lazy(s):
    f = sys._getframe(1)
    return eval(s, f.f_globals, f.f_locals)

def foo():
    a = 12
    b = 42
    print lazy("a+b")

foo()

--Guido van Rossum (home page: http://www.python.org/~guido/)