can I import the module twice (under differnet names)

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


alf <ask at me.xs4all.nl> 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
    2147483647
    >>> print foo.maxint
    2147483647
    >>> print bar.maxint
    2147483647

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




More information about the Python-list mailing list