|
|
@ -21,4 +21,13 @@ def openreadtxt(file_name):
|
|
|
|
tmp_list[-1] = tmp_list[-1].replace('\n', '') # 去掉换行符
|
|
|
|
tmp_list[-1] = tmp_list[-1].replace('\n', '') # 去掉换行符
|
|
|
|
data.append(tmp_list) # 将每行数据插入data中
|
|
|
|
data.append(tmp_list) # 将每行数据插入data中
|
|
|
|
file.close()
|
|
|
|
file.close()
|
|
|
|
return data
|
|
|
|
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()
|