Dynamically Defined Functions in Classes?

Pieter Nagel pieter at nagel.co.za
Wed Jan 31 21:45:00 EST 2001


On Wed, 31 Jan 2001, Jim Meyer wrote:

> I have an application in which I wish to treat the members of a
> dictionary as attributes;

class Bar:
    def __init__(self, initial_dict):
        self.__dict__ = initial_dict

b = Bar({'joe' : 'cool', 'frank' : 'lee', 'ron' : 'dell'})
print b.joe
b.frank = 'foo'

-- 
     ,_
     /_)              /| /
    /   i e t e r    / |/ a g e l




More information about the Python-list mailing list