Ok I have two modules, each containing a class, the problem is their classes reference each other.
Lets say for example I had a room module and a person module containin
No need to import CRoom
You don't use CRoom
in person.py
, so don't import it. Due to dynamic binding, Python doesn't need to "see all class definitions at compile time".
If you actually do use CRoom
in person.py
, then change from room import CRoom
to import room
and use module-qualified form room.CRoom
. See Effbot's Circular Imports for details.
Sidenote: you probably have an error in Self.NextId += 1
line. It increments NextId
of instance, not NextId
of class. To increment class's counter use CRoom.NextId += 1
or Self.__class__.NextId += 1
.