<ScreenOptions>
<ScreenOption Visible="true" Locked="false" PrintCode="" DataType="Boolean" Description="Sill Support <br> (Champagne or Mill Finish sill support is always provided when jamb depth > 8-5/8�)" ValueDescription="No" Sequence="1">
<ComponentAttributeId>622</ComponentAttributeId>
</ScreenOption>
</ScreenOptions>
嗨,如何用空值替换这个字符�?
open('decmpresed.txt', 'r') as file :
filedata = file.read()
print(filedata)
# Replace the target string
filedata = filedata.replace('�', ' ')
# # Write the file out again
with open('decompresed.txt', 'w') as file:
file.write(filedata)
到目前为止,这段代码还不适用于我,有什么想法吗?
发布于 2022-10-05 18:48:34
您看到的是Unicode替换字符U+FFFD。这意味着您的Unicode XML文件被错误地处理了。每当您看到�符号时,信息就丢失了,无法恢复。没有办法拿回旧的数据。
我的想法是:无论您从哪里获得这个XML,都让它们生成一个正确的XML文件。
您是链中的下一个不了解Unicode的人,您将消除数据已经丢失的明确指示。你在隐藏窃听器。从长远来看,我不认为那会有什么好结果。
打开文件时,可以指定编码。
with open('decmpresed.txt', 'r', encoding='utf-16-le') as file:
或者不管文件编码是什么。一旦你得到正确的编码,替换就会工作。
https://stackoverflow.com/questions/73964879
复制相似问题