Alex Rivera | Logout

Using module's own objects in __main__.py

Asked 2010-08-05T02:15:58.987
47

I’m trying to access a module’s data from inside its __main__.py.

The structure is as follows:

mymod/
    __init__.py
    __main__.py

Now, if I expose a variable in __init__.py like this:

__all__ = ['foo']
foo = {'bar': 'baz'}

How can I access foo from __main__.py?

Edit
Report

1 Answer

1

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.

answered 2012-05-10T19:57:17.970

Your Answer