[Chicago] =?gb2312?q?=BB=D8=B8=B4=A3=BA=20Re:=20=20re=A3=BA=20=20re=A3=BA?= =?gb2312?q?=20Re:=20=20UnicodeDecodeError=20When=20compiling=20BitTorrent?= =?gb2312?q?=20in=20BitTornado?=
=?gb2312?q?=B7=C5=DC=F8=20=CC=B8?=
jolley84 at yahoo.com.cn
Wed Oct 11 11:49:20 CEST 2006
thanks the problem is solved,thx.and can i ask a second question?
how to debug in python environment?i mean detecting and fixing bugs.
thanks
jolley
Ian Bicking <ianb at colorstudy.com> дµÀ£º
·ÅÜø ̸ wrote:
>
> also to supplement it, my file system encoding is "mbcs",and the default
> encoding is "ascii".
Well, I should say that you've unintentionally gotten into a rather
difficult place in Python. Anyway, I'll suggest an expedient fix that
might work for you, but only if mbcs is a superset of ASCII.
You can do this to set the default encoding (which is currently 'ascii'):
import sys
reload(sys)
sys.setdefaultencoding('mbcs')
Do this early in the process, and when Python doesn't know what the
encoding of a string is it will guess mbcs. If mbcs is not a superset
of ASCII then this will probably cause all kinds of havoc. Otherwise...
> thanks.
> jolley
> */·ÅÜø ̸ /* дµÀ£º
>
> first, as a newbie, i may ask some foolish problems, pls be patient
> and endurable.
> second, i have done this after your explanation:
>
> from sys import getfilesystemencoding
> path.decode(sys.getfilesystemencoding)
Note this doesn't do anything, you have to do:
path = path.decode(sys.getfilesystemencoding())
> path = ("\\").decode(sys.getfilesystemencoding())
> +b.decode(sys.getfilesystemencoding())
Perhaps the best strategy is not to try to use unicode strings at all.
It's only when you mix a unicode string and an encoded non-ascii string
that you get problems. If they are all encoded strings, it should work
(assuming your encodings are consistent -- if you use utf8 one place and
mbcs elsewhere it will be break things).
This function can be used to encode things:
def encode_mbcs(s):
if isinstance(s, unicode):
return s.encode('mbcs')
else:
return s
Then use this around any string that is acting funny.
--
Ian Bicking | ianb at colorstudy.com | http://blog.ianbicking.org
_______________________________________________
Chicago mailing list
Chicago at python.org
http://mail.python.org/mailman/listinfo/chicago
---------------------------------
Mp3·è¿ñËÑ-иèÈȸè¸ßËÙÏÂ
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.python.org/pipermail/chicago/attachments/20061011/3001678d/attachment-0001.htm
More information about the Chicago
mailing list