首页 > 编程语言 > 详细

python文件内容修改

时间:2018-08-04 17:13:59      阅读:141      评论:0      收藏:0      [点我收藏+]
#!/usr/bin/env python
# -*- coding: UTF-8 -*-
def alter(file,old_str,new_str):
    file_data = ""
    with open(file, "r", ) as f:
        for line in f:
            if old_str in line:
                line = line.replace(old_str,new_str)
            file_data += line
    with open(file,"w",) as f:
        f.write(file_data)

alter("@option.file_path@", "@option.old_file@", "@option.new_file@")

 

python文件内容修改

原文:https://www.cnblogs.com/niwajiang1/p/9419048.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!