[Python-Dev] open(): set the default encoding to 'utf-8' in Python 3.3?

Michael Foord fuzzyman at voidspace.org.uk
Tue Jun 28 18:50:29 CEST 2011

On 28/06/2011 17:34, Terry Reedy wrote:
> On 6/28/2011 10:48 AM, Michael Foord wrote:
>> On 28/06/2011 15:36, Terry Reedy wrote:
>>> S = open('myfile.txt').read()
>>> now return a text string in both Py2 and Py3 and a subsequent
>>> 'abc' in S
>>> works in both.
>> Nope, it returns a bytestring in Python 2.
> Which, in Py2 is a str() object. 

Yes, but not a "text string". The equivalent of the Python 2 str in 
Python 3 is bytes. Irrelevant discussion anyway.

> In both Pythons, .read() in default mode returns an object of type 
> str() and 'abc' is an object of type str() and so expressions 
> involving undecorated string literals and input just work, but would 
> not work if input defaulted to bytes in Py 3. Sorry if I was not clear 
> enough.
Well, I think you're both right. Both semantics break some assumption or 

All the best,



May you do good and not evil
May you find forgiveness for yourself and forgive others
May you share freely, never taking more than you give.
-- the sqlite blessing http://www.sqlite.org/different.html

More information about the Python-Dev mailing list