List of declared variables in interactive Python session?
Raymond Arthur St. Marie II of III
rastm2 at aol.commorespam
Sun Jul 20 19:30:24 EDT 2003
>"Raymond Arthur St. Marie II of III" wrote:
>>
>> >>> vars( )
>>
>> {'d': 'pywin', '__builtins__': <module '__builtin__' (built-in)>,
>'__name__':
>> '__main__', 'pywin': <module 'pywin' from
>> 'C:\PYTHON22\lib\site-packages\Pythonwin\pywin\__init__.pyc'>, '__doc__':
>None}
>>
>> >>> for v in vars(): print v
>> ...
>>
>> Traceback (most recent call last):
>> File "<interactive input>", line 1, in ?
>> RuntimeError: dictionary changed size during iteration
>
>for v in vars().copy(): print v
>
>works fine...
>
>-Peter
>
Very nice Peter, I didn't see that coming (sad for me). But it amounts to the
same thing, really. Newbies might like to know that you work with a variable
declared specially for this "for" iterater in hopes that you won't stomp all
over a variable you might otherwise clobber.
Only, I love a good one-liner. :-)
Ray --
More information about the Python-list
mailing list