文件读写(python 3.5)
来源:互联网 发布:淘宝店铺入驻蘑菇街 编辑:程序博客网 时间:2024/05/17 01:10
写文件:
#coding=utf8 #!/usr/bin/env python'makeTextFile.py--create text file'import os#ls=os.linesepls='\n'#get filenamefname='e:/myfile.txt'while True:if os.path.exists(fname):print("Error:'%s' already exists" % fname)else:break#get file content(text) linesall=[]print("\nEnter lines ('.' by itself to quit).\n")#loop until user terminates inputwhile True:entry=input('> ')if entry=='.':breakelse:all.append(entry)#write lines to file with proper line-endingfobj=open(fname,'w')fobj.writelines(['%s%s'%(x,ls) for x in all])fobj.close()print('DONE')
读文件:
#!/usr/bin/env python'readTextFile.py--read and display text file'#get filenamefname='e:/1.txt'fname=input('Enter filename:')print()#attemp to open file for readingtry:fobj=open(fname,'r')except IOError as e:print("*** file open error:",e)else:#display contents to the screenfor eachLine in fobj:print(eachLine,end='')fobj.close()
0 0
- 文件读写(python 3.5)
- Python学习(文件读写)
- python--python读写文件
- Python学习笔记(3)--文件读写
- Python 中的文件读写(一)
- Python 中的文件读写(二)
- Python读写Excel 2007文件(xlsx)
- (4)Python读写csv文件
- python 读写csv文件(一)
- Python读写Excel 2007文件(xlsx)
- Python学习笔记(二):文件读写
- excel文件读写(python版)
- python文件读写最佳实践(with)
- Python读写Unicode文件
- python Ini文件读写
- Python读写文件
- Python读写文件
- Python读写ini文件
- FancyDialog对话框
- 如何理解Android ContentProvider
- 剑指offer33:把数组排成最小的数
- 变量的解构赋值
- Git版本管理学习与应用
- 文件读写(python 3.5)
- 《Java高并发程序设计》学习 --7.1 Akka之Hello World
- 常用显示接口技术
- React-native学习过程 六 flexbox伸缩容器属性
- Ubuntu处于一直连接状态,却连不上网
- <xsl:sort>对多个字段进行排序
- POJ1789-Truck History (prim裸)
- 生日蜡烛
- Windows加载器与模块初始化