[ Web Proxy ]
URL:
Viewing: https://wiki.python.org/moin/../python/platforms/../gui/../../python/archive/DefaultEncoding.html [Back]  [Original]

Default Encoding - Python Wiki
Python Wiki
psf/wiki 0 0
Copy page

Default Encoding

Legacy Wiki Page

This page was migrated from the old MoinMoin-based wiki. Information may be outdated or no longer applicable. For current documentation, see python.org.

Python users who are new to Unicode sometimes are attracted by default encoding returned by sys.getdefaultencoding(). The first thing you should know about default encoding is that you dont need to care about it. Its value should be ascii and it is used when converting byte strings StrIsNotAString to unicode strings. As in this example:

   1 a = "abc" + u"bcd"

When you concatenate byte string abc with unicode string ubcd Python will first convert abc into uabc by calling abc.decode(sys.getdefaultencoding()). If you put non-ascii characters into byte string then .decode(sys.getdefaultencoding()) method will fail with UnicodeDecodeError, therefore byte strings should not contain non-ascii characters. In Python3.0 sys.getdefaultencoding will be removed.


CategoryUnicode

Back to top

Web Proxy Viewer  |  New URL  |  Original Page