[docs] cannot set default encoding in python3.3.3

Zachary Ware zachary.ware+pytut at gmail.com
Mon Feb 17 17:59:58 CET 2014


On Sun, Feb 16, 2014 at 7:19 AM, gby <gby_sdu at 163.com> wrote:
> Dear sir:
>     In python 2.7,we can set the default encoding by:
>
>     import sys
>     reload(sys)
>     sys.setdefaultencoding('gbk')
>
>     But in python3.3, the default encoding is 'utf-8' and I can't set it
> 'gbk' ! The "sys.setdefaultencoding()" function is disappeared !
>     I am really worried,I have tried several days but I can't solve it !
> Please help me and show me how to set the default encoding in python 3.3,
> please!

First off, this is not the right place to send this kind of question.
docs at python.org is geared towards discussion of the documentation of
Python, not its usage.  In future, send this kind of question to
python-list at python.org or tutor at python.org, where many knowledgeable
people are listening in and willing to help.

With that out of the way: Sorry, but the answer here is "don't".
Googling for "python setdefaultencoding" will give you many results
saying why it's a bad idea in 2.7, and impossible in 3.x.  The real
solution is to make sure to decode all input to unicode (the unicode
type in 2.7, str in 3.3) as early as possible, and encode all output
to bytes (str type in 2.7, bytes in 3.3) as late as possible.  If you
need help with this, please ask on tutor at python.org.

Hope this helps,

-- 
Zach


More information about the docs mailing list