Unsupported characters in input

允我心安 提交于 2019-12-01 03:58:53

问题


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

or

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.

How can I extract, delete those characters from the text, or is there anything to do , so python will support this kind of input.

I've tried to converted it into others format like ansi, utf, etc. but without success.

P.S.: I'm using python 2.7


回答1:


Set the source file encoding accordingly to the actual encoding of the file, so that the interpreter knows how to parse it.

For instance, if you use UTF-8, just add this string to the header of the file:

    # -*- coding: utf8 -*-

It must be the first or the second line of the file. See PEP 0263: Defining Python Source Code Encodings.




回答2:


Just a hint (waiting for the actual code): prepend u to the string to mark it as unicode.

u"/ËstraɪkɪÅ/"


来源:https://stackoverflow.com/questions/4873543/unsupported-characters-in-input

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!