I'm having trouble with python inheritance.
This example only outlines the hierarchy for a far more complicated code I can't post here, so bear with me while I give you all the details needed.
I have defined two classes:
class A(pydot.Node):
def __init__(self):
# do some init
pydot.Node.__init__(self)
def very_useful_method(self):
return self._valuable_property
class B(A):
def __init__(self):
# do some initialization
A.__init__(self)
if "__main__" == __name__
# some code that uses add_node and get_nodes
retrieved_b_instance.very_useful_method() #error, **Node** object has no attribute very_useful_method...
I'm pretty convinced I didn't get the inheritance process right, and that I'm doing something wrong with the __init__
calls.
I'm using python 2.7.
Any advice?
Trace:
Traceback (most recent call last):
File "/home/reuts/PycharmProjects/AI4/Ex4_pydot.py", line 399, in <module>
driver.interact()
File "/home/reuts/PycharmProjects/AI4/Ex4_pydot.py", line 362, in interact
self.parse_command(cmd)
File "/home/reuts/PycharmProjects/AI4/Ex4_pydot.py", line 354, in parse_command
options[args[0]]()
File "/home/reuts/PycharmProjects/AI4/Ex4_pydot.py", line 344, in print_report
print "node cpt: %s" % node.get_cpt()
AttributeError: 'Node' object has no attribute 'get_cpt'
Node is the base class from pydot's implementation (pydot.Node), on top of that there are two more classes I used while inheriting from pydot.Node.
I've now examined the code in pydot.py and I'm suspecting there is a conversion there. Coming from a Java and static-type background I'm slow in understanding the operations in get_node_list() and their effects on the returned instance's type.