More on

Levente Sandor nospam at newsranger.com
Sat Jul 14 12:46:54 CEST 2001


In article <9ioru01pc9 at enews4.newsguy.com>, Alex Martelli says...
>
>"Levente Sandor" <nospam at newsranger.com> wrote in message
>news:poP37.19002$Kf3.249024 at www.newsranger.com...
>> If you absolutely need a 'with' statement...
>>
>> import re
>> def with(object, statements):
>> """ 'with' for the very lazy programmer :) :) :)
>> Someone might prefer Ctrl+C, Ctrl+V, ... instead."""
>> exec(re.sub('\B\.', '%s.' % object, statements))
>
>If you're willing to stoop to an exec, then surely it's
>better to use the fact that exec lets you specify local
>and global dictionaries:
>
>def with(obj, statements, globs=None):
>    if globs is None: globs=globals()
>    exec statements in vars(obj), globs
>

Sorry but I can't see how it simulates the 'with' statement in Pascal or VB.
Levi





More information about the Python-list mailing list