More on "with" statement

Levente Sandor nospam at newsranger.com
Sat Jul 14 13:38:07 EDT 2001


Very nice!
Thanks,
Levi

>> Sorry but I can't see how it simulates the 'with' statement in Pascal or
>VB.
>
>That's probably because I had switched the two dictionaries
>in the exec statement -- here's a corrected, simpler version:
>
>>>> def with(obj,stmt):
>...   exec stmt in globals(), vars(obj)
>...
>>>> with(x, "pak=23; pok=24")
>>>> x.pak
>23
>>>> x.pok
>24
>>>>
>
>In lieu of globals() one surely wants to default to the *caller*'s
>globals, sys._getframe(1).f_globals, of course.
>
>
>Alex
>
>
>





More information about the Python-list mailing list