解决UnicodeDecodeError问题

今天写wxPython时,发现一个问题:

UnicodeDecodeError: ‘gbk’ codec can’t decode bytes in position 2-3: illegal multibyte sequence

但我在代码头有注释

#!/usr/bin/env python
#-*- coding: UTF-8 -*-

这是为什么呢.我把UTF-8改为GBK后就一切正常了,后来问了下limodou,原来是unicode的问题,我自己安装的wxPython是unicode版本的,不是ansi的,所以,在里面所有字符都是以unicode对象存在的,而ansi的就以string对象存在,所以对于“中国”这种中文字符显然就要用u”中国”来代替

这是wxPython官方的话

The Win32 version of wxPython is distributed as a set of standard self-installing executables. This allows you the convenience of using the Start Menu and Add/Remove Programs just like any other Windows software.

There are two versions of wxPython for each of the supported Python versions on Win32. They are nearly identical, except one of them has been compiled with support for the Unicode version of the platform APIs. Unless you’ve been told differently, you probably want to get the Unicode build of wxPython. Although they are not nativly Unicode like NT-based systems, the Unicode build of wxPython will also mostly work on Windows 98/Me systems using a Microsoft hack called MSLU (or unicows.dll) that translates unicode API calls to ansi API calls. However the coverage of the API is not complete so there are some difficult bugs lurking in there, so the best thing to do is to upgrade your machines if possible, otherwise Windows 98/Me users may want to try the ANSI build instead.

 
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值