> This all begs the question: why is there a default? and why is the > default a guess? > > I have to admit that I was completely oblivious to this potential > pitfall, and mostly that's because in the most common case, I am working > with ASCII files.
You answered your own question: it is this reason why there is a default for the IO encoding. > It's just serendipity that most systems specify (if > not require) the locale encoding be an ASCII superset. No, it's not. It is deliberate that the locale's encoding is an ASCII superset. On systems where it isn't, users are typically well aware that they are not using ASCII. On the systems where it is, users get completely oblivious of the entire issue. > I already know that this suggestion will not get any following because, > for most people, it just works. However: "In the face of ambiguity, > refuse the temptation to guess." Would it really be that unfortunate to > force everyone to reconsider what they are doing when they open() files? Yes, definitely. It is this very reasoning that caused Python 2.x to use ASCII as the default encoding (when mixing strings and unicode), and, for the entire lifetime of 2.x, has caused endless pain for developers, which simply fail to understand the notion of encodings in the first place. The majority of developers is unable to get it right, in particular if their native language is English. These developers just hate Unicode. They google for solutions, and come up with all kinds of proposals which are all wrong (such as reloading the sys module to get back sys.setdefaultencoding, to then set it to UTF-8). So for the limited case of text IO, Python 3.x now makes a guess. However, this guess is not in the face of ambiguity: it is the locale that the user (or his administrator) has selected, which identifies the language that they speak and the character encoding they use for text. So if Python also uses that encoding, it's not really an ambiguous guess. Regards, Martin _______________________________________________ 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