Alp*_*gut 5 python unicode python-2.x
我想为变量分配一串字符,但它说
: there isn't a "code to show.
Run Code Online (Sandbox Code Playgroud)
我有一个我想要分配给变量的字符串
d="stunning:/ËstÊnɪÅ/"
Unsupported characters in input
Run Code Online (Sandbox Code Playgroud)
要么
word="stuning:/?stra?k??/"
Unsupported characters in input
Run Code Online (Sandbox Code Playgroud)
所以基本上解释器不允许我将它分配给变量,所以我不能对它进行编码.
如何从文本中提取,删除这些字符,或者有什么要做,所以python将支持这种输入.
我试图将它转换成其他格式,如ansi,utf等,但没有成功.
PS:我正在使用python 2.7
根据文件的实际编码设置源文件编码,以便解释器知道如何解析它.
例如,如果您使用UTF-8,只需将此字符串添加到文件的标题中:
# -*- coding: utf8 -*-
Run Code Online (Sandbox Code Playgroud)
它必须是文件的第一行或第二行.请参阅PEP 0263:定义Python源代码编码.