Login | Register For Free | Help
Search for: (Advanced)

Mailing List Archive: Python: Python

__import__ returns module without it's attributes?

 

 

Python python RSS feed   Index | Next | Previous | View Threaded


zac256 at gmail

Nov 13, 2009, 3:27 PM

Post #1 of 3 (185 views)
Permalink
__import__ returns module without it's attributes?

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
--
http://mail.python.org/mailman/listinfo/python-list


davea at ieee

Nov 14, 2009, 8:05 AM

Post #2 of 3 (168 views)
Permalink
Re: __import__ returns module without it's attributes? [In reply to]

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
--
http://mail.python.org/mailman/listinfo/python-list


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

Python python RSS feed   Index | Next | Previous | View Threaded
 
 


Interested in having your list archived? Contact Gossamer Threads
 
  Web Applications & Managed Hosting Powered by Gossamer Threads Inc.