views:

837

answers:

3

In Python, is it possible to define an alias for an imported module?

For instance:

import a_ridiculously_long_module_name

...so that is has an alias of 'short_name'.

+15  A: 
import a_ridiculously_long_module_name as short_name

also works for

import module.submodule.subsubmodule as short_name
vartec
I'll give you answer since you were in first - thanks!
j0rd4n
+3  A: 

Check here

import module as name

or

from relative_module import identifier as name
Brian R. Bondy
+1  A: 

If you've done:

import long_module_name

you can also give it an alias by:

lmn = long_module_name

There's no reason to do it this way in code, but I sometimes find it useful in the interactive interpreter.

John Fouhy