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. >> 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. 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. -- Marc-Andre Lemburg eGenix.com Professional Python Services directly from the Source (#1, Jan 21 2010) >>> Python/Zope Consulting and Support ... http://www.egenix.com/ >>> mxODBC.Zope.Database.Adapter ... http://zope.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ ::: Try our new mxODBC.Connect Python Database Interface for free ! :::: eGenix.com Software, Skills and Services GmbH Pastor-Loeh-Str.48 D-40764 Langenfeld, Germany. CEO Dipl.-Math. Marc-Andre Lemburg Registered at Amtsgericht Duesseldorf: HRB 46611 http://www.egenix.com/company/contact/ _______________________________________________ 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