Dynamically creating class properties

Karlo Lozovina _karlo_ at _mosor.net
Thu Oct 4 22:59:57 CEST 2007

Hi all,

this is my problem: lets say I have a arbitrary long list of attributes 
that I want to attach to some class, for example:

     l = ['item1', 'item2', 'item3']

Using metaclasses I managed to create a class with those three 
attributes just fine. But now I need those attributes to be properties, 
so for example if 'A' is my constructed class, and 'a' an instance of 
that class:

    a = A()

Now if I write:

    a.item1 = 'something'
    print a.item1

I want it to be actually:

    print a.getitem1

Any idea how to do that with metaclasses and arbitrary long list of 
attributes? I just started working with them, and it's driving me nuts :).

Thanks for the help,
best regards.

Karlo Lozovina -- Mosor

More information about the Python-list mailing list