Python读取文件并修改文件内容后保存为新文件

xueshancun 20 0 PDF 2021-02-17 20:02:14

下面是例子是读取一个文件内容,并且改变其中满足正则的行,进行内容追加。 # use command : reWriteFile.py oldFileName.txt newFileName.txt import re import sys param = sys.argv if len(param) > 3: sys.exit() oldFile = param[1] newFile = open(param[2], "w+") with open(oFile) as f2: while True: line = f2.readline() # read con

用户评论
请输入评论内容
评分:
暂无评论