Mutually referencing imports -- impossible?
matt at tplus1.com
Sun Jul 13 19:55:04 CEST 2008
I started off with a module that defined a class Vehicle, and then
subclasses Car and Motorcycle.
In the Car class, for some bizarre reason, I instantiated a Motorcycle.
Please pretend that this can't be avoided for now.
Meanwhile, my Motorcycle class instantiated a Car as well.
Then I moved the Car and Motorcycle classes into separate files. Each
imported the Vehicle module.
Then I discovered that my Car module failed because the global
Motorcycle wasn't defined. The same problem happened in my Motorcycle
module. Car and Motorcycle can't both import each other.
In the beginning, when all three (Vehicle, Car, and Motorcycle) were
defined in the same file, everything worked fine.
I don't know how to split them out in separate files now though and I
really wish I could because the single file is enormous.
More information about the Python-list