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

Mark Lawrence breamoreboy at yahoo.co.uk
Tue Sep 18 19:47:07 EDT 2012


On 18/09/2012 21:10, porkfried wrote:
> 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
>

If you could state what you're trying to achieve rather than how you're 
trying to achieve it then perhaps people could give you a solution to 
your problem.

-- 
Cheers.

Mark Lawrence.




More information about the Python-list mailing list