In Python, how can I access the namespace of the main module from an imported module?

module, namespaces, python

Solution

import __main__

But don't do this.

Problem

Specifically, I need to get at some objects and globals from the main module in an imported module. I know how to find those things when the parent module wants some particular thing from a child module, but I can't figure out how to go in the other direction.

Original source