How to get current module object
Alex
noname9968 at gmail.com
Tue Feb 19 00:33:52 EST 2008
Gabriel Genellina wrote:
> En Mon, 18 Feb 2008 14:49:02 -0200, Alex <noname9968 at gmail.com> escribió:
>> That's what I've been searching for, thanks. By the way, I know it might
>> be trivial question... but function and class namespaces have __name__
>> attribute too. Why is global one always returned?
> I don't understand the question (even with the later correction
> namespaces->objects)
There's no question anymore, I just failed to distinguish function local
variables (which don't include __name__) and function object's attributes
>>> Why do you want to get the module object? globals() returns the module
>>> namespace, its __dict__, perhaps its only useful attribute...
>>>
>> To pass it as a parameter to a function (in another module), so it can
>> work with several modules ("plugins" for main program) in a similar
>> manner.
>>
>
> The function could receive a namespace to work with (a dictionary). Then
> you just call it with globals() == the namespace of the calling module.
Yes, but access to module seems more verbose:
>>> module_dict['x']()
xxx
Instead of just:
>>> module.x()
xxx
More information about the Python-list
mailing list