What is the Python equivalent to the C++ namespace?
The closest in spirit would be to use a module.
In a file lower_level.py
you'd have
def do_stuff():
pass
and then elsewhere you'd do:
import lower_level
lower_level.do_stuff()
EDIT / addendums: That's the simple way. There's things like packages, where you'd have a folder lower_level
, and inside that folder is an __init__.py
identifying lower_level
as a package. Inside that package you'd have .py
files that'd be modules, or you put certain imports and declarations into the __init__.py
. But it can also just remain empty. I guess packages would amount to nested namespaces.
- prog.py
\MyNameSpaceA
- __init__.py # just an empty file
- ObjA.py # A python Module
\SubPackageB
- __init__.py
- ObjB.py # another python module