出現這個問題的主要原因是因為python2的編碼是ASCII碼,文件中有中文的話就得使用utf8編碼,只需要在文件的頭部加上以下其中一種標注:
一、在文件頭部添加如下注釋碼:
# coding=<encoding name> 例如,可添加# coding=utf-8
二、在文件頭部添加如下兩行注釋碼:
#!/usr/bin/python
# -*- coding: <encoding name> -*- 例如,可添加# -*- coding: utf-8 -*-
三、在文件頭部添加如下兩行注釋碼:
#!/usr/bin/python
# vim: set fileencoding=<encoding name> : 例如,可添加# vim: set fileencoding=utf-8 :