__import__ returns module without it's attributes?
Gabriel Genellina
gagsl-py2 at yahoo.com.ar
Sun Nov 15 11:32:01 EST 2009
En Fri, 13 Nov 2009 20:27:29 -0300, Zac Burns <zac256 at gmail.com> escribió:
> I've overloaded __import__ to modify modules after they are
> imported... but running dir(module) on the result only returns
> __builtins__, __doc__, __file__,
> __name__, __package__, and __path__.
>
> Why is this? More importantly, where can I hook in that would allow me
> to see the contents of the module?
Post some code. This works for me:
py> import __builtin__
py> builtin_import = __builtin__.__import__
py> def __import__(*args):
... module = builtin_import(*args)
... module.__signature__ = "kilroywashere"
... return module
...
py> __builtin__.__import__ = __import__
py>
py> import htmllib
py> dir(htmllib)
['AS_IS', 'HTMLParseError', 'HTMLParser', '__all__', '__builtins__',
'__doc__', '__file__', '__name__', '__package__', '__signature__',
'sgmllib', 'test']
py> htmllib.__signature__
'kilroywashere'
--
Gabriel Genellina
More information about the Python-list
mailing list