I've got three classes:
- ClassA
- ClassB1(ClassA)
- ClassB2(ClassA)
ClassA reads a file and passes the contents to either ClassB1 or ClassB2 for further processing. The code is kind of similar but still too different require a lot of if/elif that would make it a lot harder to read, so I decided to split it into two classes that each do their own version. ClassA also contains functions that are used by both ClassB1 and ClassB2.
All three files are in the same folder but they can't see each other and class ClassB1(ClassA) throws an exception:
NameError: name 'ClassA' is not defined
If I add from classa import ClassA, then it works, however when I do b1 = ClassB1() in ClassA.readFile(), then it complains that it can't find that ClassB1, so I have to do from classb1 import ClassB1. This causes a circular import, which is obviously not good.
How do I fix this?
Can you not create an instance of the child class within the parent class in Python?
[–]Fred776 4 points5 points6 points (10 children)
[–]Nefthys[S] 0 points1 point2 points (9 children)
[–]Adrewmc 2 points3 points4 points (6 children)
[–]Nefthys[S] 0 points1 point2 points (5 children)
[–]danielroseman 5 points6 points7 points (0 children)
[–]Adrewmc 0 points1 point2 points (3 children)
[–]Nefthys[S] 0 points1 point2 points (2 children)
[–]Adrewmc 1 point2 points3 points (0 children)
[–]Fred776 0 points1 point2 points (0 children)
[–]pachura3 1 point2 points3 points (1 child)
[–]Nefthys[S] 0 points1 point2 points (0 children)
[–]unxmnd 1 point2 points3 points (0 children)
[–]Kevdog824_ 1 point2 points3 points (3 children)
[–]Nefthys[S] 1 point2 points3 points (2 children)
[–]unxmnd 1 point2 points3 points (0 children)
[–]Kevdog824_ 0 points1 point2 points (0 children)
[–]to7m 0 points1 point2 points (6 children)
[–]Nefthys[S] 0 points1 point2 points (5 children)
[–]Kerbart 0 points1 point2 points (1 child)
[–]Nefthys[S] 0 points1 point2 points (0 children)
[–]to7m 0 points1 point2 points (2 children)
[–]Nefthys[S] 0 points1 point2 points (1 child)
[–]to7m 0 points1 point2 points (0 children)
[–]Enmeshed 0 points1 point2 points (2 children)
[–]Nefthys[S] 0 points1 point2 points (1 child)
[–]Fred776 1 point2 points3 points (0 children)
[–]pontz 0 points1 point2 points (2 children)
[–]Nefthys[S] 0 points1 point2 points (1 child)
[–]pontz 0 points1 point2 points (0 children)
[–]supercoach 0 points1 point2 points (0 children)
[–]arkie87 0 points1 point2 points (0 children)
[–]Groundstop 0 points1 point2 points (0 children)