On Dec 28, 7:29 am, "Martin v. Loewis" <mar...@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]()

--
-- 
http://mail.python.org/mailman/listinfo/python-list

Reply via email to