#总结函数的好处:代码重用,保持一致性,可扩展性
import time
def logger():
time_format = "%Y-%m-%d %X"
time_current = time.strftime(time_format)
with open("a.txt","a+") as f:
f.write("%s end action\n" %time_current)
def test1():
print("in the test1")
logger()
def test2():
print("in the test2")
logger()
def test3():
print("in the test3")
logger()
test1() #运行函数
test2()
test3()
函数的好处
最新推荐文章于 2024-08-23 13:31:41 发布
该博客展示了如何使用Python的logger函数来记录程序运行日志。通过定义一个logger函数,实现了在不同函数中调用并记录当前时间,将日志追加到文件a.txt中。同时,logger函数在test1、test2和test3三个测试函数中被调用,展示了其代码重用性和一致性。
1725

被折叠的 条评论
为什么被折叠?



