can I import the module twice (under differnet names)

Ben Finney bignose+hates-spam at
Thu Nov 2 06:55:31 CET 2006

alf <ask at> writes:

> wonder if in the python I could treat modules imorts like classes
> instances. It means I could import it twice or more times under
> different names.

No need to import more than once. The 'import' statement binds a
module object to the specified name, and you can bind as many names as
you like to the same object.

    >>> import sys
    >>> foo = sys
    >>> bar = sys
    >>> print sys.maxint
    >>> print foo.maxint
    >>> print bar.maxint

 \           "Laugh and the world laughs with you; snore and you sleep |
  `\                                             alone."  -- Anonymous |
_o__)                                                                  |
Ben Finney

More information about the Python-list mailing list