简体   繁体   English

我有unicode的python问题

[英]I have a python Issue with unicode

I have a dictionary in a specific file, when I try to run it from other file importing it: 当我尝试从导入它的其他文件运行它时,我在特定文件中有一个字典:

import resultado
print ( resultado.dic["10101027"])

I have the following error: 我有以下错误:

SyntaxError: (unicode error) 'utf-8' codec can't decode byte 0xba in position 38: invalid start byte

resultado file:

dic = {

"10101027":"UNIDAD EDUCATIVA DISTRITAL ANTONIO ORNESBARRIO SAN JOSE COTIZA FRENTE CALLE LOS EUCALIPTUS. DERECHA ESCALERA SAN MARCOS. IZQUIERDA ESCALERA SAN JUDA FRENTE AL PARQUE ANDRES GALARRAGA EDIFICIO",
"10101001":"UNIDAD EDUCATIVA DISTRITAL MADARIAGASECTOR ALTAGRACIA DERECHA CALLE CONCORDIA. IZQUIERDA CALLE DELICIAS. FRENTE CALLE DELICIAS A CONCORDIA AL FRENTE COLEGIO BELUTINI CASA",
"10101002":"UNIDAD EDUCATIVA SANTA BARBARASECTOR SANTA BARBARA DERECHA CALLE PARAISO. IZQUIERDA CALLE DOCTOR GONZALEZ. FRENTE CALLE PARAISO FRENTE ESQUINAS DOCTOR GONZALEZ A PARAISO EDIFICIO",
}

The message seems pretty clear, at least with respect to the limited amount of information you provide: you've got a byte 186 (0xba) in one of the files, which means Python fails to parse the file as UTF-8. 该消息看起来非常清晰,至少就您提供的信息量而言:在其中一个文件中有一个字节186(0xba),这意味着Python无法将文件解析为UTF-8。

In ISO-8859-1, 0xba is "º", so if you see this character (likely in a string) when opening files it's possible that your editor automatically infers encoding when not UTF-8, and that the file is either mis-written or mis-declared as UTF-8. 在ISO-8859-1中,0xba为“º”,因此,如果在打开文件时看到此字符(可能在字符串中),则编辑器可能会在非UTF-8时自动推断编码,并且该文件可能是错误的-书面或错误声明为UTF-8。

Without the exact file content as-is (copy/paste might be subject to automated transcoding from your editor) it's hard to say more. 如果没有按原样提供确切的文件内容(复制/粘贴可能会受到编辑器的自动转码的影响),那么很难说更多。 You may want to run the file utility on your various files to see what that says though. 您可能要在各种文件上运行file实用程序,以查看显示的内容。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM