Python 之 open() 和file()
来源:互联网 发布:数据库项目经理的收获 编辑:程序博客网 时间:2024/06/06 03:24
如何打开文件
handle=open(file_name,access_mode="r")
file_name 变量包含我们希望打开的文件的字符串名称,access_mode 中的'r'表示读取,‘w’表示写入,'a'表示添加,其它可能用到的标实还有‘+’表示读写,‘b’表示2进制访问,如果未提供access_mode,默认为“r”.
如果open()成功,一个文件对象句柄会被返回。
filename=raw_input('enter file')
fobj=open(filename,'r')
for eachline in fobj:
print eachline,
fobj.close()
#还记得 print 后面跟的“,”是什么意思吧,表示【每次打印都不换行,而是间隔空格】
fobj=open(filename,'r')
for eachline in fobj:
print eachline,
fobj.close()
#还记得 print 后面跟的“,”是什么意思吧,表示【每次打印都不换行,而是间隔空格】
file()内建函数它的功能等于open(),但是可以看出,他是个文件工厂(生成文件对象),类似于int()生成整型对象,dict()生成字典对象,后面会学习
0 0
- Python 之 open() 和file()
- 【python】file.write() 和 open()
- Python的file()和open()方法的区别
- Python中file()和open()的区别
- open file in python demo
- python-4-之with和open对比
- python os.open() 和open()
- file,open和Inf,NaN
- python之open()函数
- 在python下file类型、open方法
- Python编程->cannot open file 'python27_d.lib'
- Python IOError: File not open for writing
- Python入门:PIL(pillow)之im对象(Image.open('file.jpeg'))
- Python 用file 对象和open方法处理文件的区别
- python: cannot open shared object file: No such file
- shell之lsof(list open file)
- 文件和内建函数 open() 、file()
- Open File& New File之MFC后台代码分析
- Java中创建对象的5种不同方法
- Python函数的内嵌,嵌套函数
- 【U盘】U盘乱码
- 欢迎使用CSDN-markdown编辑器
- VI模拟2D峰函数的等高线
- Python 之 open() 和file()
- Android L 64位兼容32 应用程序的认识
- SVM原理篇
- 高并发的核心技术-幂等的实现方案
- 欢迎使用CSDN-markdown编辑器
- finally中的代码块在什么情况下不会被执行
- 超强、超详细Redis数据库入门教程
- ASP.NET Web API(一)
- 协方差矩阵、相关矩阵、相关系数矩阵、相关系数之间的关系