I want to subclass a python dictionary to create a new class with dynamic keys. In other words the key value is 'property(fset, fget, fdel, doc)'.
For some reason the when I get the d key, a property object is return instead of the function get_b.
d should return the value of d but instead returns a property object
d.fget() returns the value i want.
Where did I go wrong?
class mydict(dict):
def __init__(self, arg):
self['a'] = arg
self['b'] = property(self.get_b)
def get_b(self):
return self['a']
#--------------------EXAMPLE--------------------
d = mydict(5)
print 'a = ', d['a'] # Returns 5
print 'b = ', d['b'] # Incorrect. Returns <property obeject>. Should return 5.
print 'fget =', d['b'].fget() # Correct. Returns 5.