Importing Modules

Devan L devlai at gmail.com
Wed Nov 2 01:28:06 EST 2005


Sam Pointon wrote:
> On the second point, a combination of sys.path, os.listdir and
> __import__ should do what you're after, although sifting through the
> whole of sys.path and subfolders from Python, rather than the
> interpreter itself, could be slow.  (And it'll be redundant as well -
> __import__ will have do the same thing, though you could fix that by
> using the imp module).
>
> -Should- work, but not tested, so don't blame me if it doesn't:
>
[code]

__import__(modulename) is not equivalent to import modulename;
__import__ returns a module object

>>> __import__('pickle')
<module 'pickle' from 'E:\Python23\lib\pickle.py'>
>>> pickle




More information about the Python-list mailing list