Python替换文件中的文本
例子
import fileinputreplacements = {'Search1': 'Replace1',
'Search2': 'Replace2'}
for line in fileinput.input('filename.txt', inplace=True):
for search_for in replacements:
replace_with = replacements[search_for]
line = line.replace(search_for, replace_with)
print(line, end='')
以上是 Python替换文件中的文本 的全部内容, 来源链接: utcz.com/z/325137.html