Importing a module using a different name

To import a module (but not a function) using a different name, type import, the module name, as, and the name you want to use. For example:

import tinymodule as mymod

Tip Although it's not common, you can also combine the from import and import as syntax, as follows:

from tinymodule import myfunction as a function

REMEMBER If you import a module using a different name, the local namespace won't know the real module name; it will know the module only by the name you used to import it. REMEMBER The syntax for giving a local name to a function is different from the syntax for calling a function and giving a name to the result. When you call a function, you add parentheses at the end of the function name:

myresult = tinymodule.tinyfunction(2)

Was this article helpful?

0 0

Post a comment