输入中不支持的字符 [英] Unsupported characters in input
问题描述
我想将一串字符分配给一个变量,但它说
I want to assign a string of characters to a variable but it says
: there isn't a "code to show.
我有一个字符串要分配给一个变量
I have a string that i want to assign to a variable
d="stunning:/ËstÊnɪÅ/"
Unsupported characters in input
或
word="stuning:/ˈstraɪkɪŋ/"
Unsupported characters in input
所以基本上解释器不允许我将它分配给一个变量,所以我不能在它上面编码.
so basically the interpreter doesn't allow me to assign it to a variable, so I can't code on it.
如何从文本中提取、删除这些字符,或者有什么可做的,所以python会支持这种输入.
How can I extract, delete those characters from the text, or is there anything to do , so python will support this kind of input.
我尝试将其转换为 ansi、utf 等其他格式,但没有成功.
I've tried to converted it into others format like ansi, utf, etc. but without success.
P.S.:我使用的是 python 2.7
P.S.: I'm using python 2.7
推荐答案
根据文件的实际编码相应地设置源文件编码,以便解释器知道如何解析它.
Set the source file encoding accordingly to the actual encoding of the file, so that the interpreter knows how to parse it.
例如,如果您使用 UTF-8,只需将此字符串添加到文件头:
For instance, if you use UTF-8, just add this string to the header of the file:
# -*- coding: utf8 -*-
它必须是文件的第一行或第二行.请参阅PEP 0263:定义 Python 源代码编码.
It must be the first or the second line of the file. See PEP 0263: Defining Python Source Code Encodings.
这篇关于输入中不支持的字符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!