动态调用python类和函数

class test1(object):
    def __init__(self):
        print "i am test1"

class test2(object):
    def __init__(self):
        print "i am test2"

#  method 1
class_name = 'test1'
eval(class_name)()


# method 2
def exec_class(name):
    name()
exec_class(test2)


函数

def show():
    print 'I am show'

def talk():
    print 'I am talk'

method = 'show'
eval(method)()




 

posted on 2013-08-12 19:26  you Richer  阅读(329)  评论(0)    收藏  举报