最新文章专题视频专题问答1问答10问答100问答1000问答2000关键字专题1关键字专题50关键字专题500关键字专题1500TAG最新视频文章推荐1 推荐3 推荐5 推荐7 推荐9 推荐11 推荐13 推荐15 推荐17 推荐19 推荐21 推荐23 推荐25 推荐27 推荐29 推荐31 推荐33 推荐35 推荐37视频文章20视频文章30视频文章40视频文章50视频文章60 视频文章70视频文章80视频文章90视频文章100视频文章120视频文章140 视频2关键字专题关键字专题tag2tag3文章专题文章专题2文章索引1文章索引2文章索引3文章索引4文章索引5123456789101112131415文章专题3
当前位置: 首页 - 科技 - 知识百科 - 正文

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

来源:动视网 责编:小OO 时间:2020-11-27 14:21:55
文档

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

实例如下所示。#coding=utf-8';';';Created on 2012-5-29@author: xiaochou';';';import osimport timedef nsfile(s): ';';';The number of new expected documents';';';#判断文件夹是否存在,如果不存在则创建 b = os.path.exists(";E: estFile";) if b: print(";File Exist
推荐度:
导读实例如下所示。#coding=utf-8';';';Created on 2012-5-29@author: xiaochou';';';import osimport timedef nsfile(s): ';';';The number of new expected documents';';';#判断文件夹是否存在,如果不存在则创建 b = os.path.exists(";E: estFile";) if b: print(";File Exist


下面为大家分享一篇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创建文件的简单实例

实例如下所示。#coding=utf-8';';';Created on 2012-5-29@author: xiaochou';';';import osimport timedef nsfile(s): ';';';The number of new expected documents';';';#判断文件夹是否存在,如果不存在则创建 b = os.path.exists(";E: estFile";) if b: print(";File Exist
推荐度:
标签: 文件 简单 File
  • 热门焦点

最新推荐

猜你喜欢

热门推荐

专题
Top