无法弄清楚为什么这不起作用,它只是输出一堆“跳过文件”
我正在尝试将文件夹中的所有文件中的 =+ 替换为 =
import os
directory_path=os.path.dirname(os.path.abspath(__file__))
files = os.listdir(directory_path)
for each_file in files:
with open(os.path.join(directory_path, each_file), 'r+') as file:
file.replace('=+', '=')
好的,我相信您一直在使用与“utf-8”不同的编码,您可以检查一下:
for each_file in files:
with open(os.path.join(directory_path, each_file), mode='r', encoding='ISO-8859-1') as file:
filedata = file.read()
filedata = filedata.replace('=+', '=')
with open(os.path.join(directory_path, each_file), mode='w', encoding='ISO-8859-1') as file:
file.write(filedata)
让我知道这现在是否有效。
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句