Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Re: __import__ returns module without it's attributes?

2 views
Skip to first unread message

Dave Angel

unread,
Nov 14, 2009, 11:05:44 AM11/14/09
to Zac Burns, pytho...@python.org

Zac Burns wrote:
> 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?
>
> --
> Zachary Burns
> (407)590-4814
> Aim - Zac256FL
> Production Engineer (Digital Overlord)
> Zindagi Games
>
>
I'm probably not the one to give you the actual answer (at least not in
the next couple of days), but I could help you ask a better question.

Provide a simple example of your code, and what it does. Describe the
python version and OS platform you're running it on. And detail the
contents of any extra files or environment values that are needed to
reproduce the problem.

(You may find http://www.catb.org/~esr/faqs/smart-questions.html useful)

BTW, I don't know of any method __import__(), only a builtin function,
so I don't see how you can overload it. But your example should make it
clear what you really meant.

HTH
DaveA

Gabriel Genellina

unread,
Nov 15, 2009, 11:32:01 AM11/15/09
to pytho...@python.org
En Fri, 13 Nov 2009 20:27:29 -0300, Zac Burns <zac...@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

0 new messages