Importing items from inside a module stores their names in the namespace, which gives you direct access to the items—you don't have to type the module name to use them. But this method doesn't store the name of the module in the namespace.
To import the function that's inside tinymodule, type this:
>>> from tinymodule import tinyfunction
To check what's stored in the namespace, type dir(). Note: If you didn't quit Python after doing the example in the previous section, "Importing by name," you might see other names as well when you type dir().
Tip Importing a module by name is the recommended way of getting access to a module and its functions. Although importing items from inside a module is useful in some situations, this can cause problems if the items have the same names as other items you're working with.
Was this article helpful?