python文件读写demo
2013-11-24 16:06
225 查看
python按行读取文件
python在文件头部插入内容
#! /usr/bin/python srcFile = "test.src" #root of src file dstFile = "test.dst" #root of dst file sf = open(srcFile , 'r') df = open(dstFile , 'w') for line in sf: #here you can do something with line df.write(line) sf.close() df.close()
python在文件头部插入内容
#! /usr/bin/python File = "test.src" #root of file file = open(File , 'r') HistoryContent = file.read() file.close() file = open(srcFile , 'w') file.write("new content\n")#here can be replaced by new content file.write(HistoryContent) file.close()
相关文章推荐
- Python读写/追加excel文件Demo分享
- Python读写文件Demo
- python 中文件读写模式一定要注意
- python 文件读写查找、替换相关简单操作
- Python文件读写常见用法总结
- python-ConfigParser模块【读写配置文件】
- 【Python】修改文件并立即写回到原始位置(inplace读写)
- 【python学习笔记】pthon3.x中的文件读写操作
- python文件读写实例学习笔记
- Python文件读写 - 读一个文件所有行,加工后写另一个文件
- Python读写CSV文件
- python读写不同编码txt文件--转自CSDN
- Python 对 Excel 文件的读写
- Python编程:yaml文件读写
- Python 读写文件
- Python基础——读写文件
- Python 文件读写
- Python文件操作,open读写文件,追加文本内容
- Python open读写文件实现脚本
- Python读写配置文件的实际操作步骤解析