how to get my own namespace ?
stef mientki
stef.mientki at gmail.com
Tue Oct 16 17:39:44 EDT 2007
Robert Kern wrote:
> stef mientki wrote:
>
>> I want to view my own namespace,
>> i.e. to see the modules namespace in the module itself,
>> is that possible ?
>>
>> I can use
>> dir()
>> but I read dir is just a convenience function,
>> and besides I want key/value pairs.
>>
>
> vars() will give you a dictionary copy of the local namespace, but modifying it
> won't modify the namespace.
>
> globals() will give you the module's namespace as a dictionary which you can modify.
>
> locals() will give you the local namespace (wherever you happen to be), but you
> may be restricted from modifying that dictionary in some circumstances.
>
>
thanks Robert,
funny,
that this is much more complicated than __dict__ of an external module:
- you have to make a copy before iterating
- iterating more than once increases the list
I think I just write a module on top.
cheers,
Stef Mientki
More information about the Python-list
mailing list