Unsupported input characters

I want to assign a character string 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 

therefore, basically the interpreter does not allow me to assign it to a variable, so I can not code it.

How can I extract, remove these characters from text, or do something, so python will support this type of input.

I tried to convert it to other formats like ansi, utf, etc., but without success.

PS: I am using python 2.7

+4
source share
2 answers

Set the encoding of the source file according to the actual encoding of the file so that the interpreter knows how to analyze it.

For example, if you are using UTF-8, simply add this line to the file header:

  # -*- coding: utf8 -*- 

This should be the first or second line of the file. See PEP 0263: Defining Python Source Codes .

+7
source

Just a hint (waiting for real code): add u to the string to mark it as Unicode.

 u"/ËstraɪkɪÅ/" 
+2
source

Source: https://habr.com/ru/post/1338080/


All Articles