Python读写文件及文件指针定位
2009-08-07 20:19
369 查看
读文件用read,传递要读的字节数
写文件用write,传递要写的字符串
1. 写文件
2. 读文件
write只能写字符串,要写其他类型的数据,得用pickle这个包
写文件用write,传递要写的字符串
1. 写文件
>>> f = open('e://test.txt','w') >>> a = [1, 2] >>> f.write(a); Traceback (most recent call last): File "<pyshell#13>", line 1, in <module> f.write(a); TypeError: write() argument 1 must be str, not list >>> f.write('hello world'); 11 >>> f.close() >>>
2. 读文件
>>> f = open('e://test.txt', 'r') >>> f.read(5) 'hello' >>> f.seek(0, 1) 5 >>> f.read() ' world' >>> f.seek(0, 0) 0 >>> f.read() 'hello world' >>> f.close() >>>
write只能写字符串,要写其他类型的数据,得用pickle这个包
相关文章推荐
- Python(2.7.6) ConfigParser - 读写配置文件
- Python 文件读写操作实例详解
- Python 文件读写操作实例详解
- python读写matlab文件.mat
- Python3 读写文件
- 【python学习笔记】pthon3.x中的文件读写操作
- python学习之路三(文件读写)
- python写的读写文件的脚本
- Python读写文件乱码问题
- Python读写txt文件
- python文件读写
- python文件读写
- Python文件操作读写文件
- python文件读写出现乱码总结
- python之读写excel文件
- 「python」文件的随机读写
- Python文件读写
- python-ConfigParser模块【读写配置文件】
- python文件读写
- python 二进制读写文件