What is the difference between module and namespace in python?
i have read some articles which may denotes both namespace and module for
import foo
import bar from foo
import bar from foo as baz
part of a script.
What is the difference between module and namespace in python?
i have read some articles which may denotes both namespace and module for
import foo
import bar from foo
import bar from foo as baz
part of a script.
Module is basically a file that has your code in it and namespace is basically the name you had defined for your class, function, variables and etc in the module.
Python module is basically your python file like filename.py
. In the above case, I believe foo
is a python module and bar
namespace is what you want to import.
And the right convention to import a module or a module namespace is shown below:
# foo is the module and bar is the namespace
from foo import bar # You may use bar directly
bar() # Call bar function
# Another method:
import foo
foo.bar() # Call bar function as well
For more reading I would suggest the Python Tutorial for namespace and module