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

2012-09-18 Thread Steven D'Aprano
On Tue, 18 Sep 2012 21:38:19 -0400, Terry Reedy wrote: > On 9/18/2012 5:51 PM, Thomas Jollans wrote: >> On 09/18/2012 10:50 PM, weissman.m...@gmail.com wrote: >>> Well there's wired stuff like this: >>> >>> In [1]: locals()["x"] = 5 >>> >>> In [2]: print x >>> 5 >>> >>> >> No, there isn't. Modifyi

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

2012-09-18 Thread Terry Reedy
On 9/18/2012 5:51 PM, Thomas Jollans wrote: On 09/18/2012 10:50 PM, weissman.m...@gmail.com wrote: Well there's wired stuff like this: In [1]: locals()["x"] = 5 In [2]: print x 5 No, there isn't. Modifying the dictionary returned by locals() has no effect. Last time I tried it, it does wi

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

2012-09-18 Thread Mark Lawrence
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. Ca

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

2012-09-18 Thread Thomas Jollans
On 09/18/2012 10:50 PM, weissman.m...@gmail.com wrote: > Well there's wired stuff like this: > > In [1]: locals()["x"] = 5 > > In [2]: print x > 5 > No, there isn't. Modifying the dictionary returned by locals() has no effect. >>> def f (): ... locals()["x"] = 1 ... return x ... >>> f

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

2012-09-18 Thread weissman . mark
On Tuesday, September 18, 2012 4:10:32 PM UTC-4, 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 >

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

2012-09-18 Thread Thomas Jollans
On 09/18/2012 10:10 PM, 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 s

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

2012-09-18 Thread porkfried
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) w