python乱码处理

在.py文件第一行加上以下任意一种,只是写法不同,效果一样的。

# -*- coding: UTF-8 –*-
#vim: set fileencoding=utf-8:
# coding=utf-8

示例1:

# -*- coding: UTF-8 –*-
import sys


'''
Created on 2012-9-20

@author: Donie
'''
if __name__ == '__main__':
    
    #第一种
    #type = sys.getfilesystemencoding()
    #print "中文".decode('UTF-8').encode(type)

示例2:

# -*- coding: UTF-8 –*-

'''
Created on 2012-9-20

@author: Donie
'''
if __name__ == '__main__':
   

    #第二种
    #print '中文'.decode('utf-8').encode();

示例3:

# -*- coding: UTF-8 –*-

'''
Created on 2012-9-20

@author: Donie
'''
if __name__ == '__main__':
   
    
    #第三种直接打印
    #print "反对司法捣碎"

 

posted @ 2013-12-26 01:34  luwenbin  阅读(231)  评论(0编辑  收藏  举报