Python实现的读取文件内容并写入其他文件操作示例
作者:xuezhangjun 时间:2021-10-11 02:27:02
本文实例讲述了Python实现的读取文件内容并写入其他文件操作。分享给大家供大家参考,具体如下:
文件目录结构,如图:
read_file.py是工作文件,file_test.py是读取文件源,write_test.py是写入目标文件。
文件A:file_test.py
#coding=utf-8
for i in range(1, 10):
print i
文件B:read_file.py
# coding=utf-8
# 打开件A
f = open('./file_test.py', 'rb')
# 读取文件A内容
print '---------- read file ---------'
content = f.read()
print 'content = ', content
# 打开文件B
w = open('./write_test.py', 'wd')
print '--------- write file --------'
# 将文件A的内容,写入文件B
w.write(content)
print '--------- close file --------'
# 关闭文件B
w.close()
# 关闭文件B
f.close()
print '--------- end ----------'
文件C:write_file.py
#coding=utf-8
for i in range(1, 10):
print i
希望本文所述对大家Python程序设计有所帮助。
来源:https://blog.csdn.net/xuezhangjun0121/article/details/88584738
标签:Python,读取,写入,文件
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
Go项目配置管理神器之viper的介绍与使用详解
2023-09-17 01:05:52
![](https://img.aspxhome.com/file/2023/1/89021_0s.jpg)
php下使用iconv需要注意的问题
2023-11-23 03:05:09
python浪漫表白源码
2023-11-22 05:16:39
![](https://img.aspxhome.com/file/2023/0/67830_0s.jpg)
淘宝搜索框研究报告
2010-07-27 12:49:00
![](https://img.aspxhome.com/file/UploadPic/20107/27/2010727125528102s.png)
解析SQL Server数据体系和应用程序逻辑
2009-01-23 13:58:00
Python 对象中的数据类型
2022-01-25 00:58:35
SQL SERVER数据库开发之asp存储过程应用
2008-05-19 12:55:00
![](https://img.aspxhome.com/file/UploadPic/up/2008051913142215.jpg)
oracle 触发器 学习笔记
2009-05-24 19:57:00
彻底弄懂CSS盒子模式之一(DIV布局快速入门)
2007-05-11 17:03:00
![](https://img.aspxhome.com/file/uploadpic/20075/200751117352545.gif)
简单的网站页面有什么好处
2007-11-15 06:28:00
SQL触发器在保持数据库完整性中的实际应用
2009-10-23 14:34:00
IE9硬件加速性能远超Chrome5.0和Firefox4.0
2010-06-09 11:12:00
![](https://img.aspxhome.com/file/UploadPic/20106/9/img20100612757087130-68s.jpg)
Django自定义模板过滤器和标签的实现方法
2023-08-12 12:24:51
![](https://img.aspxhome.com/file/2023/0/71370_0s.jpg)
利用CSS属性实现进度条的方式
2010-02-25 12:31:00
oracle逻辑运算符与其优先级简介
2023-07-15 00:28:26
Python学习之装饰器与类的装饰器详解
2023-11-23 20:04:07
asp版FCKEditor编辑器的用法
2008-07-05 12:15:00
Web页脚设计的版权格式规范
2009-07-22 20:52:00
![](https://img.aspxhome.com/file/UploadPic/20097/22/01-17s.gif)
python 删除指定时间间隔之前的文件实例
2023-07-19 17:58:38
数据库连接字符串的常见问题和解决方法
2008-11-28 15:16:00