dictionary - Python: casting a classobj into a dict -


i'm wondering how feel idea of being able generate dictionary of information regarding fields of object documentation purposes? imagine this

class myobject():   def __init__(self):     self.a = objecta()     self.b = objectb()     self.c = objectc()   @staticmethod   def __iter__():     yield ('a', 'description of relation between myobject , objecta instance')     yield ('b', 'description of relation between myobject , objectb instance')     yield ('c', 'description of relation between myobject , objectc instance') 

and on command line this:

>>> dict(myobject) {'a': 'description of relation between myobject , objecta instance',   'b': 'description of relation between myobject , objectb instance',    'c': 'description of relation between myobject , objectc instance'} 

does mechanism exist python (i'm on 2.x)?

if not, think start making switch python 3 if feature implemented


Comments