def foo(x):
    barleycode = """
    def barley(y):
        print "barley's x =", x
        print "barley's y =", y
    """
barleywrap, barley = wrap_f(barleycode, globals(), locals(), 'barleywrap',
    'barley')
barley('this string')
print() 
x = 'modified x'
barley = barleywrap(**locals())
barley('new arg')
print() 
x = 're-modified x'
barley("doesn't see the re-mod.")
x = 'the global x'
foo('outer arg')
Captured variables in "eval" in Python