How to create an object instance from a string??

Tian wangtianthu at gmail.com
Sat Mar 19 17:16:42 EST 2005


How can I create an instance of an object from a string?

For example, I have a class Dog:
class Dog:
  def bark(self):
    print "Arf!!!"


I have a string:
classname = "Dog"

How can I create a instance of Dog from classname?
Is there any such methods like those in Java?




More information about the Python-list mailing list