标签:python inpu encoding replace str lap import pre ace
#程序1: 实现简单的shell sed替换功能 import sys,os old_file = open(‘test.txt‘,‘r‘,encoding=‘utf-8‘) new_file = open(‘test_bak.txt‘,‘w‘,encoding=‘utf-8‘) old_line = input(‘替换前内容>>:‘) new_line = input(‘替换后内容>>:‘) for line in old_file: #print(line.strip()) if old_line in line: line = line.replace(old_line,new_line) new_file.write(line) old_file.close() new_file.close()
Python自动化开发—EX.3(实简单的shell sed功能)
标签:python inpu encoding replace str lap import pre ace
原文地址:https://www.cnblogs.com/Dashuang/p/9452926.html