Circular imports in Python
I have to say that this restriction has bitten me so many times now and it's one lame restriction.
Basically, Python has an awful support for circular imports, a simple example: # a.py
import b
x = 1
# b.py
import a
x = a.x + 1 #circular definition, x isn't defined
Now I understand why it's like this (Python is very dynamic and import is a executable statement yada yada), but a lot of times it's just useful for two modules to reuse each others code. Here are some examples of this:
Now a solution for this could be to create more modules or do some hacks, but generally, I really hope they solve this issue since it's really annoying and prevents some designs. Circular imports are solved in languages such as Perl or Java. |
|