檔案內容替換
# fileName 檔案名
# oldStr 源字串
# newStr 新字串
def fileContentAlter(fileName, oldStr, newStr):
file_datahttps://www.cnblogs.com/WebLinuxStudy/p/= ""
with open(fileName, "r", encoding="utf-8") as f:
for line in f:
line = line.replace(oldStr, newStr)
file_data += line
with open(fileName, "w", encoding="utf-8") as f:
f.write(file_data)
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/184536.html
標籤:Python
