If you are specifically importing a class, then the syntax is something like:
from file import Class1
That means no other entities were imported into the namespace.
More generally, if you import using a wildcard
from file import *
then you will import everything not beginning with '_' in that module or package (the __init__.py
file in the file package directory). If __all__
is defined in that module or package, then it will only import the symbols from that list.
Lastly, if you do a straight import of a module or package, then all symbols from that module or package are imported:
import file
from package import file
Note - file here is the filename minus the `.py` extension - I used that because that was in the OP's example.
Note - technically, all defined things are accessible - but python assumes you are accessing things you were meant to access. You would need to chain the namespaces together:
file.file2.class2
But this is bad since it may violate the "interface" the module or package was trying to define for you.
Note - modules define their interface using the `__all__` variable. A package is a directory with an `__init__.py` module in it. But the `__all__` list only works when you use the `from x import *` format.