动态调用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)()




 

你可能感兴趣的:(python)