Instantiate an object based on a variable name

Diez B. Roggisch deets at nospam.web.de
Thu Dec 31 12:05:46 EST 2009


Wells schrieb:
> Sorry, this is totally basic, but my Google-fu is failing:
> 
> I have a variable foo. I want to instantiate a class based on its
> value- how can I do this?


class Foo(object):
      pass


ze_class = Foo

f = ze_class()


Diez



More information about the Python-list mailing list