Circular reference between modules?
Question: If have this module

    
    
    # mymodule.py
    import __main__
    

And I import it in the python interpreter:

    
    
    >>> import mymodule
    >>> dir(mymodule)
    ['__builtins__', '__doc__', '__file__', '__main__', '__name__', '__package__']
    >>> dir()
    ['__builtins__', '__doc__', '__name__', '__package__', 'mymodule']
    >>> import sys
    >>> sys.modules['__main__'] == mymodule.__main__
    True
    >>> mymodule == mymodule.__main__.mymodule
    True
    

I've just created a circular reference by importing a module that imports
`__main__`. Is this bad?


Answer: No. Python has no problem with circular references like this. The only thing
you must be sure of is that you don't use a name from the other module until
it has been defined.

