
gagsl-py2 at yahoo
Nov 15, 2009, 8:32 AM
Post #3 of 3
(160 views)
Permalink
|
|
Re: __import__ returns module without it's attributes?
[In reply to]
|
|
En Fri, 13 Nov 2009 20:27:29 -0300, Zac Burns <zac256 [at] gmail> 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 -- http://mail.python.org/mailman/listinfo/python-list
|