diff --git a/getdata.py b/getdata.py index d18b888..e4902ba 100644 --- a/getdata.py +++ b/getdata.py @@ -21,4 +21,13 @@ def openreadtxt(file_name): tmp_list[-1] = tmp_list[-1].replace('\n', '') # 去掉换行符 data.append(tmp_list) # 将每行数据插入data中 file.close() - return data \ No newline at end of file + return data + +def updateFile(file, old_str, new_str): + with open(file, "r", encoding="utf-8") as f1, open("%s.bak" % file, "w", encoding="utf-8") as f2: + for line in f1: + f2.write(re.sub(old_str, new_str, line)) + os.remove(file) + os.rename("%s.bak" % file, file) + f2.close() + f1.close() \ No newline at end of file