我不明白为什么这不能工作,它只是输出了一堆“跳过文件”
我正在尝试用=替换文件夹中所有文件中的=+
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('=+', '=')发布于 2020-05-17 10:56:14
好的,我相信你一直在使用与'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)现在让我知道这是否有效。
https://stackoverflow.com/questions/61846188
复制相似问题