I learned from websitethat that I have to add a code declaration in python when I don't enter friendly Unicode characters: http://www.python.org/dev/peps/pep-0263/ , but I still feel embarrassed about it .
Suppose I work on linux with vim, and I create a new py file and input codes as follows:
#!/usr/bin/python2.7
1 . I tried replacing line 2 with codes as follows:
import sys reload(sys) sys.setdefaultencoding('utf8')
but it doesn’t work, right?
2 . I am not very familiar with linux, I really do not know why I should add _*_ at the beginning and at the end of delcaration code, and when I tried to replace # -*- coding: utf8 -*- with # code=utf8 or # code: utf8 , I got an error
File "pythontest.py", line 3 SyntaxError: Non-ASCII character '\xde' in file pythontest.py on line 3, but no encoding declared; see http://www.python.org/peps/pep-0263.html for details
but this code declaration is mentioned at http://www.python.org/dev/peps/pep-0263/ !
and in accordance with the documentation, code declaration is allowed as follows:
Oh what is that? I do not think that this can be recognized by a computer. What was the code supposed to declare in the world? I feel more and more confused.
Thanks for the help.
Searene
source share