import time as t
from os import path
def createFile(dest):
date = t.localtime(t.time())
name = '%d_%d_%d.txt' %(date[1],date[2],(date[0] %100)) # 2017 % 100 = 17
if not (path.isfile(dest+name)):
f = open(dest+name,'w')
f.write('
'*30)
f.close()
if __name__ == '__main__':
destination = '<PATH>'
createFile(destination)
raw_input('done')
查看当前目录下所要创建的6_11_17.txt
文件是否已经存在,如果不存在就创建,并写入30个换行('
'*30
)
要点:
- 所要读写的文件名可以是_变量_