import time def logger(): with open(‘a.txt‘,‘a+‘) as f: time_format = ‘%Y-%m-%d %X‘ time_current = time.strftime(time_format) f.write(‘%s end action\n‘ % time_current) def test1(): ‘‘‘testing1‘‘‘ print (‘test1 starting action...‘) logger() def test2(): ‘‘‘testing2‘‘‘ print (‘test2 starting action...‘) logger() def test3(): ‘‘‘testing3‘‘‘ print(‘test3 starting action...‘) logger() test1() test2() test3() #代码重用 #保持一致性 #可扩展
时间: 2024-12-05 02:52:36