Issue
How to make child class constructor from another child class in python3?
May be I need to make some class preinit import? All classes is in one file, so I can't import it
class Parent():
def __init__(self):
print "Parent"
class ChildOne(Parent):
two = ChildTwo() # Not works!!! How to make it works???
def __init__(self):
Parent.__init__(self)
two.print_two()
def print_one(self):
print "One"
class ChildTwo(Parent):
one = ChildOne() # This works!!!
def __init__(self):
Parent.__init__(self)
one.print_one()
def print_two(self):
print "Two"
Solution
There is no way to do this because you got recursion between child classes. Only one way is to move this print_one and print_two to Parent Class and use it from parent.
Answered By - Real Lord
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.