实例如下所示:
#coding=utf-8 ''' Created on 2012-5-29 @author: xiaochou ''' import os import time def nsfile(s): '''The number of new expected documents''' #判断文件夹是否存在,如果不存在则创建 b = os.path.exists("E:\\testFile\\") if b: print("File Exist!") else: os.mkdir("E:\\testFile\\") #生成文件 for i in range(1,s+1): localTime = time.strftime("%Y%m%d%H%M%S",time.localtime()) #print localtime filename = "E:\\testFile\\"+localTime+".java" #a:以追加模式打开(必要时可以创建)append;b:表示二进制 f = open(filename,'ab') testnote = 'private String username' f.write(testnote.encode('utf-8')) f.close() #输出第几个文件和对应的文件名称 print("file"+" "+str(i)+":"+str(localTime)+".txt") time.sleep(1) print("ALL Down") time.sleep(1) if __name__ == '__main__': s = int(input("请输入需要生成的文件数:")) nsfile(s)
以上就是Python3.5 创建文件的简单实例的详细内容,更多请关注Gxl网其它相关文章!
查看更多关于Python3.5创建文件的简单实例的详细内容...
声明:本文来自网络,不代表【好得很程序员自学网】立场,转载请注明出处:http://haodehen.cn/did84052