python怎么按照顺序执行函数 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)
The End
发布于:2022-12-18,除非注明,否则均为
原创文章,转载请注明出处。
发表评论