Python3.5 创建文件

来源:互联网 发布:免费网页制作软件 编辑:程序博客网 时间:2024/06/05 23:53


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:\\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 文件,未来有时间进行开发,也算给编程,代码搬运工减少工作量





原创粉丝点击