I want to create a python class which implements an overloading constructor, but I'm not sure that my approach is the correct one (I catch the "AttributeError: can't set attribute" error). I have read something recently about using *args and **kwargs placeholders, but I want to see an implementation of this in my case. Here is the code:
class Node(object):
def __init__(self, code):
self.code = code
self.parent = None
def __init__(self, code, parent):
self.code = code
self.parent = parent
self.children = []
@property
def code(self):
return self.code
vertex1 = Node(1)
vertex2 = Node(2, vertex1)
print(str(vertex1.code) + " " + str(vertex2.code))