您的位置:首页 > 其它

解决UnicodeDecodeError: 'ascii' codec can't decode byte 0xe9 in position 0: ordinal not in range(128)

2015-01-09 11:43 756 查看
今天在编写Python gui程序时,给下拉列表ttk.Combobox插入值的时候报了一个UnicodeDecodeError: 'ascii' codec can't decode byte 0xe9 in position 0: ordinal not in range(128)错,

代码:

ttk.Combobox(self, textvariable=self.varopme, width=8, state='readonly', values=('文章管理', '评论列表'))


原因就是Python 2的str默认是ascii编码,和unicode编码冲突,就会报这个标题错误。那么该怎样解决呢?

我想到的一个办法是直接将字符串变为unicode字符串,在字符串前面加上一个u这个字符串表示的就是unicode字符串了

代码:

ttk.Combobox(self, textvariable=self.varopme, width=8, state='readonly', values=(u'文章管理', u'评论列表'))
这个问题就这样解决了
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐