Python OOP Problem

Martin v. Loewis martin at v.loewis.de
Mon Dec 28 12:38:14 EST 2009


>> name2class = { "MyObject" : MyObject,
>>                "MyOtherObject" : MyOtherObject,
>>                "Etc" : Etc }
>>
>> Then, when you receive the string class_name, you do
>>
>> o = name2class[class_name]
>> o.myfunction()
>>
> The class needs to be instantiated, so the one line should be as
> follows:
> 
> o = name2class[class_name]()

Oops - thanks for pointing that out.

Martin



More information about the Python-list mailing list