欢迎光临
我们一直在努力

python怎么按照顺序执行函数

python中按文本顺序执行函数,具体方法如下:

1.首先,新建文本文件test.txt,并在文件中添加以下内容;

func1,life is short

func2,use python

func1, hello word

2.test文件新建好后,在python中使用main函数定义执行顺序;

class Example(object):

def __init__(self):

pass

def func1(self, arg):

print 'this is func1, arg is {}.'.format(arg)

def func2(self, arg):

print 'this is func2, arg is {}.'.format(arg)

if __name__ == '__main__':

example_instance = Example()

with open('test.txt', 'r') as f:

for line in f.readlines():

function_name, args = line.strip().split(',')

getattr(example_instance, function_name)(args)

赞(0)
【声明】:本博客不参与任何交易,也非中介,仅记录个人感兴趣的主机测评结果和优惠活动,内容均不作直接、间接、法定、约定的保证。访问本博客请务必遵守有关互联网的相关法律、规定与规则。一旦您访问本博客,即表示您已经知晓并接受了此声明通告。