On 21/01/2010 12:00, M.-A. Lemburg wrote:
Michael Foord wrote:
On 21/01/2010 11:15, M.-A. Lemburg wrote:
Michael Foord wrote:

On 20/01/2010 21:37, M.-A. Lemburg wrote:

The only supported default encodings in Python are:

    Python 2.x: ASCII
    Python 3.x: UTF-8


Is this true? I thought the default encoding in Python 3 was platform
specific (i.e. cp1252 on Windows). That means files written using the
default encoding on one platform may not be read correctly on another
platform. Slightly off topic for this discussion I realise.

Yes, the above is what Python implements.

However, the default encoding is only used internally when converting
8-bit strings to Unicode.

Ok. I know when in Python 2 an implicit encode (or decode) can happen.
When in Python 3 can implicit encodes happen?
When e.g. passing a Unicode object to a C API that uses the "s#"
parser marker.

Ah right, thanks.

When it comes to I/O there are several other encodings which can get
used, e.g. stdin/out/err streams each have their own encoding
(just like arbitrary file objects), OS APIs use their own encoding,
etc.

If no encoding is given for these, Python will try to find a
reasonable default. Python 2.x and 3.x differ a lot in how this
is done.

As always: It's better not to rely on such defaults and explicitly
provide the encoding as parameter where possible.


Sure. I do worry that developers will still rely on the default behavior
assuming that Python 3 "fixes their encoding problems" and cause
cross-platform issues. But oh well.
IMHO, it would be better not to give them that feeling and
instead have the default for I/O always be UTF-8 (for Python 3.x)
regardless of what the OS, device or locale says.


Well, I agree - but Python 3.1 is now out and uses the platform specific encoding as the default filesystem encoding. To change that now would be an incompatible change.

Michael

Developers could then customize these settings as necessary
in their applications or via Python environment variables.

Working around UnicodeDecodeErrors is almost always the wrong
approach. They need to be fixed in the code by deciding what
to do on a case-by-case basis.



--
http://www.ironpythoninaction.com/
http://www.voidspace.org.uk/blog

READ CAREFULLY. By accepting and reading this email you agree, on behalf of 
your employer, to release me from all obligations and waivers arising from any 
and all NON-NEGOTIATED agreements, licenses, terms-of-service, shrinkwrap, 
clickwrap, browsewrap, confidentiality, non-disclosure, non-compete and 
acceptable use policies (”BOGUS AGREEMENTS”) that I have entered into with your 
employer, its partners, licensors, agents and assigns, in perpetuity, without 
prejudice to my ongoing rights and privileges. You further represent that you 
have the authority to release me from any BOGUS AGREEMENTS on behalf of your 
employer.


_______________________________________________
Python-Dev mailing list
Python-Dev@python.org
http://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: 
http://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com

Reply via email to