Python circular import, `from lib import module` vs `import lib.module`
Question: I have two python modules, `a.py` and `b.py`, both of which are in `lib/`
relative to the current directory. Suppose each module needs the functionality
of the other.

**a.py:**

    
    
    import lib.b
    ...
    

**b.py:**

    
    
    import lib.a
    ...
    

The above example works with

    
    
    PYTHONPATH=./lib python -c 'from lib import a, b'
    

However, if I switch the imports in `a.py` and `b.py` to `from lib import b`
and `from lib import a`, respectively, the above Python command terminates
with `ImportError`.

Could someone please explain why this breaks? I'm not trying to import any
member from either `a` or `b`. (In that case I would be importing from an
uninitialized module, as the question referenced below points out.)

### Reference:

  1. [python circular imports once again (aka what's wrong with this design)](http://stackoverflow.com/questions/3955790/python-circular-imports-once-again-aka-whats-wrong-with-this-design)


Answer: in your lib folder there is a __init__.py file? If yes you have 2 possibility:

1) __init__.py is empty and you can use from lib import a,b

a.foo b.bar

2) in your __init__.py there are istructions import a,b in this case you can
write

import lib.a as a import lib.b as b

hope this help you

