Reputation: 13914
When you import a module, python protects the namespace by importing all objects in that module as module.objectname
instead of objectname
. import module.objectname as objectname
will import the object as its original name in the module, but writing out every object in this manner would be tedious for a large module. What is the most pythonic way to import all objects in a module as their name within the module?
Upvotes: 5
Views: 2196
Reputation: 304147
You only need to use this form
import module.objectname as objectname
If you wish to alias the objectname to a different name
Usually you say
from module import objectname, objectname2, objectname3
There is no "Pythonic" way to import all the objects as from module import *
is discouraged (causes fragile code) so can hardly be called Pythonic
Upvotes: 2