I need to find all the classes and the relative value or string for a given object " EXAMPLE_1".
I tried with vars(obJ) but the result is not what I want since I need to find the name of the classes, then if it is "Operation" find again all the classes, if it's "Value" take the value inside it.
How can I loop inside the Object until the last argument is "Value"?
class Expression:
pass
class Operation(Expression):
def __init__(self, op, arg1, arg2):
self.op = op # a string; always one of '+' '-' '*' '/'
self.arg1 = arg1 # an Expression
self.arg2 = arg2 # an Expression
class Value(Expression):
def __init__(self, value):
self.value = value # an integer; always positive
EXAMPLE_1 = Operation('*',Value(2),Operation('+',Value(5),Value(7)))
When I run the code
print(vars(EXAMPLE_1))
>>> {'op': '*', 'arg1': <__main__.Value object at 0x00000263B0D381D0>, 'arg2': <__main__.Operation object at 0x00000263B0D385F8>}