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

Baptiste Carvello devel at baptiste-carvello.net
Wed Jun 29 09:21:19 CEST 2011

Le 28/06/2011 16:46, Paul Moore a écrit :
> -1. This will make things harder for simple scripts which are not
> intended to be cross-platform.
+1 to all you said.

I frequently use the python command prompt or "python -c" for various quick 
tasks (mostly on linux). I would hate to replace my ugly, but working

 >>> open('example.txt').read()

with the unnecessarily verbose

 >>> open('example.txt',encoding='utf-8').read()

When using python that way as a "swiss army knife", typing does matter.

My preferred solution would be:

>> - emit a warning if the encoding argument is not set

By the way, I just thought that for real programming, I would love to have a 
-Wcrossplatform command switch, which would warn for all unportable constructs 
in one go. That way, I don't have to remember which parts of 'os' wrap 
posix-only functionnality.


More information about the Python-Dev mailing list