【发布时间】:2015-08-04 03:04:38
【问题描述】:
使用 python 2.7..
我在下面使用将所有打印输出发送到一个名为 output.log 的文件。每次运行时如何将其发送到不同的文件...在 bash 中,我们可以声明一个名为 date 或其他内容的变量,并拥有文件名的那部分...那么我如何使用 python 实现相同的功能?
所以我的问题是..
- 每次我运行以下脚本时,我的文件都应该有一个 output_date/time.log 的命名约定
-
我如何删除超过 X 天且文件命名约定为 output_*.log 的文件
import sys f = open('output.log', 'w') sys.stdout = f print "test" f.close()
【问题讨论】:
-
查找
time和logging模块。 docs.python.org/2/library/time.htmldocs.python.org/2/library/logging.html
标签: python python-2.7