Python文件操作2
2016-08-29 18:31
113 查看
文件操作:
r 读
r+ 读写
w 写入 重新创建
w+ 读写入 重新创建
a 写入 追加 创建
a+ 读写 追加 创建
b 以二进制打开文件
U 支持所有换行符
r 读
r+ 读写
w 写入 重新创建
w+ 读写入 重新创建
a 写入 追加 创建
a+ 读写 追加 创建
b 以二进制打开文件
U 支持所有换行符
f = file('hello.txt',"a+") f.writelines('chejia\n') f.writelines('123456\n') f.flush() f.seek(0) print f.encoding print f.mode print f.tell() print f.readline() f.seek(0) print f.readlines() f.close() #文件的赋值 src = file('hello.txt','r') dst = file('hello word.txt','w') dst.write(src.read()) dst.close() src.close() #文件的删除 import os.path if os.path.exists('hello.txt'): os.remove('hello.txt') print 'del' 输出: a+ 0 chejia ['chejia\n', '123456\n'] del
相关文章推荐
- python:目录与文件操作
- 转载:python文件操作/打开/删除文件/压缩文件
- python目录及文件操作
- python文件目录操作
- python文件操作(2)--分析扫描得到的日志文件把文件状态导入Excel表格
- 利用 Python 做批量文件操作的任务
- Python实现tab文件操作
- python 文件与目录操作
- python天天进步(2)--文件操作之遍历目录
- python:目录与文件操作
- Python学习系列之异常和文件操作
- python学习(4)-文件操作
- python目录与文件操作
- python 文件与目录操作
- python文件操作
- Python文件操作
- Python 文件操作
- python中关于文件路径的简单操作
- python文件操作(1)--扫描某目录下的文件列表信息存入日志文件
- python天天进步(3)--文件操作之遍历目录