See Mechanize today, on the Internet to find examples of experiments, found that as long as the code appears in Chinese, will be error
' \xe4 ' inch 2 , but no encoding declared; see http: // python.org/dev/peps/pep-0263/for Details
Python's default encoding file is the ASCII code used
If the Python file uses non-English characters such as Chinese, it will be an error.
How to Solve
In the first line of the Python source file, add
# coding=utf-8
Or
#-*-coding:utf-8 -*-
Output
#-*-coding:utf-8 -*-string=' hello ' string
Switch
#-*-coding:utf-8 -*-string=' hello ' String. Decode ('UTF-8'
Chinese strings are stored in tuples, lists, or dictionaries, and you can call the dumps method of the JSON module
#-*-coding:utf-8-*-Import JSON print u'Hello' string='Hello'Printstring. Decode ('UTF-8') T_tuple=('Hey','Hello') T_list=['Hey','Hello'] T_dict={1:'Hey',2:'Hello'} print json.dumps (t_tuple,encoding='UTF-8', ensure_ascii=False) Print json.dumps (t_list,encoding='UTF-8', ensure_ascii=False) Print json.dumps (t_dict,encoding='UTF-8', Ensure_ascii=false)
Python in Windows Chinese display