In python, how can an object's properties be accessed without explicitly calling them? And print those properties?
Ex:
class MyClass:
def __init__(self):
self.prop1 = None
self.prop2 = 10
def print_properties(self):
# Print the property name and value
example_a = MyClass()
example_a.print_properties()
Desired output:
prop1: None
prop2: 10
Different from: using object.dict.keys() as it was pointed out that accessing the private
__dict__
methods is not advised. Linked posted is 2008 answer and doesn't define how to iterate through the object.