[英]Open accented xml file with python
I have this bit of code 我有这段代码
for xmlword in moviexmlfind:
fileinfo = jukeboxpath + xmlword + "*.xml"
for name in glob.glob(fileinfo):
If an xmlword contains an accented letter it will error saying character not in range. 如果xmlword包含带重音符号的字母,则会错误地指出字符不在范围内。
I have also tried: 我也尝试过:
if lookfor in open(lookfor + '.xml').read():
but that throws up encoding errors. 但这会引发编码错误。
How can I code it to open accented file names? 如何编码以打开带重音的文件名?
import codecs
codecs.open("some/file/with/unicode","rb",encoding="utf8")
should work fine :) (assuming its utf8 encoding in the file) 应该可以正常工作:)(假设它在文件中的utf8编码)
also I think your problem is that you are just giving the filename without the path try os.path.join(jukeboxpath,xml_file_name)
as your path instead of just xml_file_name 我也认为您的问题是您只是在不使用路径的情况下提供文件名,请尝试使用
os.path.join(jukeboxpath,xml_file_name)
作为路径,而不仅仅是xml_file_name
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.