📌  相关文章
📜  python如何替换文本中的某个字符串 - Python代码示例

📅  最后修改于: 2022-03-11 14:45:11.759000             🧑  作者: Mango

代码示例1
# Read in the file
with open('file.txt', 'r') as file :
  filedata = file.read()

# Replace the target string
filedata = filedata.replace('ram', 'abcd')

# Write the file out again
with open('file.txt', 'w') as file:
  file.write(filedata)