默认pyhon使用ASCII码来解释程序的,默认不支持中文,需要在程序的第一行或者第二行声明编码。

官方解决方案:https://www.python.org/dev/peps/pep-0263/

    To define a source code encoding, a magic comment must be placed into the source files either as first or second line in the file, such as:
# coding=<encoding name>
    or (using formats recognized by popular editors)
#!/usr/bin/python
# -*- coding: <encoding name> -*-
    or
#!/usr/bin/python
# vim: set fileencoding=<encoding name> :
04-24 21:47
查看更多