Why do python's different forms for import behave differently for circular imports? -


i'm creating python 2.7 library following directory structure:

$ pwd ~/code/myproject $ tree . |- myproject |   |-- __init__.py |   |-- exception.py |   |-- myproject.py 

here contents of 3 files:

$ cat __init__.py import myproject $ cat myproject.py . import exception $ cat exception.py . import myproject 

when import new library second project, exception in raised:

traceback (most recent call last):   <snip>   file "~/code/myproject/myproject/exception.py", line 1, in <module>     . import myproject importerror: cannot import name myproject 

i understand fix change contents of exception.py to:

import myproject 

... don't know why. best practices seem recommend using relative imports files in package. why import behaviour change when exception.py changes from . import myproject import myproject?


Comments

Popular posts from this blog

javascript - how to protect a flash video from refresh? -

android - Associate same looper with different threads -

visual studio 2010 - Connect to informix database windows form application -