fileinput已经支持就地编辑。stdout在这种情况下,它将重定向到文件:
#!/usr/bin/env python3import fileinputwith fileinput.FileInput(filename, inplace=True, backup='.bak') as file: for line in file: print(line.replace(text_to_search, replacement_text), end='')
欢迎分享,转载请注明来源:内存溢出
fileinput已经支持就地编辑。stdout在这种情况下,它将重定向到文件:
#!/usr/bin/env python3import fileinputwith fileinput.FileInput(filename, inplace=True, backup='.bak') as file: for line in file: print(line.replace(text_to_search, replacement_text), end='')
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)