How to get current module object

Gabriel Genellina gagsl-py2 at yahoo.com.ar
Mon Feb 18 15:09:19 EST 2008


En Mon, 18 Feb 2008 14:49:02 -0200, Alex <noname9968 at gmail.com> escribió:
> Gabriel Genellina wrote:

> 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)

>> 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.

-- 
Gabriel Genellina




More information about the Python-list mailing list