0

I'm tasked with making a function which looks at all of its children and aggregates all class variables of its children into one dictionary.

Basically:

BaseClass(object):
     #implementation

classA(BaseClass):
     self.var1 = 4
     self.var2 = "hi"

classB (BaseClass):
     self.var1 = [23,32]
     self.var2 = ("Hello","World")

I'd like for a function in BaseClass to basically aggregate all class variables of its children, and make it into a dictionary that looks somewhat like this:

{"classA":{"var1":4,"var2":"hi"},"classB":{"var1":[23,32],"var2":("Hello","World")}}

This is being used for data storage at the exit of a program -- Python 2.7 Thanks so much for your help

Eugene Primako
  • 2,767
  • 9
  • 26
  • 35
Oren
  • 84
  • 10
  • 1
    you should look at `__dict__`: https://docs.python.org/2/library/stdtypes.html#object.__dict__ – Matthew Story Jul 05 '18 at 23:45
  • 1
    Your use of `self` indicates that you mean instance variables as opposed to class variables. Is this correct? – figbeam Jul 06 '18 at 00:02
  • You should be able to re purpose [this](https://stackoverflow.com/questions/1251692/how-to-enumerate-an-objects-properties-in-python). – Paul Rooney Jul 06 '18 at 00:08

0 Answers0