Tian wrote:
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!!!"

def Factory(class_name):
    classes = {
        'Dog':Dog
    }
    return classes[class_name]


dog = Factory('Dog')()


--

hilsen/regards Max M, Denmark

http://www.mxm.dk/
IT's Mad Science
--
http://mail.python.org/mailman/listinfo/python-list

Reply via email to