User defined lexical scoping... can I do this?

porkfried weissman.mark at gmail.com
Tue Sep 18 16:10:32 EDT 2012


I want to define a 'with' command that makes entries
in dictionary available within the local scope, and
stores new local variables into that dictionary.  The
original scope should be restored on exit, and called
functions should not see anything special.  Can I do this?

my_dict = dict(a=1, b=2)
with MyScope(my_dict):
    print "A", a, "B", b
    x = 3
print my_dict["x"]
print x # FAIL, unbound



More information about the Python-list mailing list