Prothon should not borrow Python strings!

Fredrik Lundh fredrik at pythonware.com
Tue May 25 02:43:57 EDT 2004


Greg Ewing wrote:

> What if the file you're reading is a text file?

if you don't know what encoding a file uses, "text files" contains chunks of
binary data separated by newlines (and/or carriage return characters).

http://www.python.org/peps/pep-0320.html mentions a textfile(filename,
mode, encoding) constructor that hides the ugly "U" flag, and sets up proper
codecs, if necessary.

since you don't always know the encoding until you've looked inside the
file (cf. emacs encoding directive, Python, XML, etc), it would also be nice
to have a "setencoding" method (or a writable "encoding" attribute).  but
adding that to existing file-like objects may turn out to be a lot of work;
easy-to-find-and-use stream wrappers are probably a better idea.

</F>







More information about the Python-list mailing list