您好,欢迎来到三六零分类信息网!老站,搜索引擎当天收录,欢迎发信息

Python3.5 创建文件的简单实例

2025/6/18 6:47:35发布12次查看
下面为大家分享一篇python3.5 创建文件的简单实例,具有很好的参考价值,希望对大家有所帮助。一起过来看看吧
实例如下所示:
#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)
本想利用python 读取excel 文件,对应生成domain 文件,但是由于时间关系,暂时先不开发了,这里先生成.java 文件,未来有时间进行开发,也算给编程,代码搬运工减少工作量。
以上就是python3.5 创建文件的简单实例的详细内容。
该用户其它信息

VIP推荐

免费发布信息,免费发布B2B信息网站平台 - 三六零分类信息网 沪ICP备09012988号-2
企业名录 Product