Python OOP Problem
Anthony Tolle
anthony.tolle at gmail.com
Mon Dec 28 10:42:00 EST 2009
On Dec 28, 7:29 am, "Martin v. Loewis" <mar... at v.loewis.de> wrote:
>
> In this case (you just started to learn Python), I recommend to take
> an explicit approach. Create a dictionary that maps class names to
> classes:
>
> name2class = { "MyObject" : MyObject,
> "MyOtherObject" : MyOtherObject,
> "Etc" : Etc }
>
> Then, when you receive the string class_name, you do
>
> o = name2class[class_name]
> o.myfunction()
>
> HTH,
> Martin
The class needs to be instantiated, so the one line should be as
follows:
o = name2class[class_name]()
--
More information about the Python-list
mailing list