![图片[1]-怎么用Python替换文件中的内容?-uusu优素-乐高,模型,3d打印,编程](http://uusucn.zbbe.cn/wp-content/uploads/2024/01/5ee9dec58fafa376.jpg)
1、Python替换文件中内容代码:
defmodify_text():
withopen('test.txt',"r+")asf:
read_data=f.read()
f.seek(0)
f.truncate()#清空文件
f.write(read_data.replace('apple','android'))
if__name__=='__main__':
modify_text()
2、运行前后结果对比
运行前文件:

运行后文件:
原文来自:https://www.py.cn© 版权声明
文章版权归作者所有,未经允许请勿转载。
THE END



















































暂无评论内容