0

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.

MS.
  • 145
  • 1
  • 10
  • Possible duplicate of [Namespace vs regular package](https://stackoverflow.com/questions/21819649/namespace-vs-regular-package) – Avery Apr 02 '19 at 14:21
  • 4
    [What is a namespace](https://docs.python.org/3/tutorial/classes.html#python-scopes-and-namespaces) and [What is a module](https://docs.python.org/3/tutorial/modules.html#modules) – han solo Apr 02 '19 at 14:22
  • A namespace is a concept whereas a module is an implementation of this concept. – Louis Saglio Apr 02 '19 at 14:30

1 Answers1

0

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