Kat*_*ina 11 python unicode encoding nlp
我正在编写一个.py文件,其中包含来自多个字符集的字符串,包括英语,西班牙语和俄语.例如,我有类似的东西:
string_en = "The quick brown fox jumped over the lazy dog."
string_es = "El veloz murciélago hindú comía feliz cardillo y kiwi."
string_ru = "? ????? ??? ??? ?? ??????? ??, ?? ????????? ?????????!"
Run Code Online (Sandbox Code Playgroud)
我无法弄清楚如何编码我的文件,以避免在我的文件运行时生成如下所示的语法错误:
SyntaxError: Non-ASCII character '\xc3' in file example.py on line 128, but no encoding
declared; see http://www.python.org/peps/pep-0263.html for details
Run Code Online (Sandbox Code Playgroud)
我已经尝试添加# -*- coding: utf-8 -*-到我的文件的开头,但没有任何运气.我也尝试将我的字符串标记为unicode(即string_en = u'The quick brown fox jumped over the lazy dog."),再次失败.
是否可以在一个文件中包含来自不同Python编解码器的字符,或者我是否尝试执行不允许的操作?