python--文件读写
2013-09-28 23:38
120 查看
一次性读入文件到列表,速度较快,适用文件比较小的情况下
逐行读入,速度较慢,适用没有足够内存读取整个文件(文件太大)
写文件 write 与 writelines 的区别
Fd.write(str) : 把str写到文件中,write()并不会在str后加上一个换行符
Fd.writelines(content) : 把content的内容全部写到文件中,原样写入,不会在每行后面加上任何东西
track_file = "track_stock.conf" fd = open(track_file) content_list = fd.readlines() fd.close() for line in content_list: print line
逐行读入,速度较慢,适用没有足够内存读取整个文件(文件太大)
fd = open(file_path) fd.seek(0) title = fd.readline() keyword = fd.readline() uuid = fd.readline() fd.close()
写文件 write 与 writelines 的区别
Fd.write(str) : 把str写到文件中,write()并不会在str后加上一个换行符
Fd.writelines(content) : 把content的内容全部写到文件中,原样写入,不会在每行后面加上任何东西
相关文章推荐
- python 笔记 之 文件读写
- 一个简单的python读写文件脚本
- python中读写文件
- C++读写文件代码自动生成器(python3完成)
- Python之文件操作:文件的读写
- Python3学习笔记7-文件的读写
- Python 读写文件 错误TypeError: write() argument must be str, not bytes+
- python编程练习----对文件进行简单的操作(读写)
- Python文件读写,分读写成三个文件形式
- python 文件读写
- Python自动化测试 -ConfigParser模块读写配置文件
- Python对csv文件的读写
- Python读写配置文件的实际操作步骤解析
- python在window下读写文件中的中文
- python中读写文件及中文编码处理方法
- Python读写文件
- The python challenge 02————字典、读写文件、raw string
- python读写文件
- python读写二进制文件
- Python文件读写基础