Python中文乱码

今天写了一个Python的类,如下:

 1 #-*- coding:utf-8 -*-  
 2 
 3 class boy():
 4     gender = 1
 5     
 6     def __init__(self,name):
 7         self.name = name
 8         print name
 9         
10 lilei = boy('李磊')

输出结果为:

输出的是乱码,略加修改第八行代码如下:

 1 #-*- coding:utf-8 -*-  
 2 
 3 class boy():
 4     gender = 1
 5     
 6     def __init__(self,name):
 7         self.name = name
 8         print name.decode('utf-8')
 9         
10 lilei = boy('李磊')

显示正确结果:

参考:

http://blog.csdn.net/samxx8/article/details/6286407

http://www.jb51.net/article/26543.htm

posted @ 2014-12-08 18:14  _No.47  阅读(623)  评论(0编辑  收藏  举报