I would like to know how to convert a python object from a dictionary (using python3 btw). I realize that this question has been asked (and answered) already (here). However, in my case the object is given entirely in terms of @property
values, for example:
class Test:
@property
def value(self):
return 1.0
Regarding conversion to a dictionary: The __dict__
dictionary of the Test
class is empty, and consequently, the vars
function does not work as expected:
>>> vars(Test())
{}
Still, I can use gettattr(Test(), 'value')
, to obtain 1.0
, so
the value is present.
Note: The reason I am coming up with this apparently contrived example is that I am trying to convert a cython cdef class
(containing parameters) to a dictionary. The recommended way to wrap c structures with properties using cython is indeed based on properties.