I’m trying to access a module’s data from inside its __main__.py.
__main__.py
The structure is as follows:
mymod/ __init__.py __main__.py
Now, if I expose a variable in __init__.py like this:
__init__.py
__all__ = ['foo'] foo = {'bar': 'baz'}
How can I access foo from __main__.py?
foo
If you run the module with python -m mymod then code in __main__.py will be able to import from the rest of the module without having to add the module to sys.path.
python -m mymod
sys.path