python- 按照日期格式(xxxx-xx-xx)每日生成一个文件

时间:2017-04-12 23:06:14   收藏:0   阅读:1645

请按照这样的日期格式(xxxx-xx-xx)每日生成一个文件,例如今天生成的文件为2013-09-23.log, 并且把磁盘的使用情况写到到这个文件中。

#!/usr/bin/env python
#!coding=utf-8
import time
import os
new_time
= time.strftime(%Y-%m-%d) //time.strftime()可以用来获得当前时间,可以将时间格式化为字符串
disk_status
= os.popen(df -h).readlines() str1 = ‘‘.join(disk_status) // join() 方法用于将序列中的元素以指定的字符连接生成一个新的字符串
f
= file(new_time+.log,w) f.write(%s % str1) f.flush() f.close()

 

评论(0
© 2014 mamicode.com 版权所有 京ICP备13008772号-2  联系我们:gaon5@hotmail.com
迷上了代码!