python怎么按照顺序执行函数

859
2021/1/28 14:02:38
栏目: 编程语言
开发者测试专用服务器限时活动,0元免费领,库存有限,领完即止! 点击查看>>

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)

辰迅云「云服务器」,即开即用、新一代英特尔至强铂金CPU、三副本存储NVMe SSD云盘,价格低至29元/月。点击查看>>

推荐阅读: python中xpath安装的方法是什么