Phillip J. Eby wrote:
Here's a rough draft:
def textopen(name, mode="r", encoding=None): if "U" not in mode: mode += "U" if encoding: return codecs.open(name, mode, encoding) return file(name, mode)
Nice. It should probably also check whether there's a 'b' or 't' in 'mode' and raise an error if so. I'd also prefer to call it 'textfile', as that reads more nicely with "for line in textfile(...):" use cases, and it does return a file object.
textfile was my original proposal: http://mail.python.org/pipermail/python-dev/2002-March/021115.html but that was made at a time when it wasn't clear if "open" or "file" would be the preferred way to open a file. now that we've settled on the verb form, I think "textopen" or "opentext" would be slightly more consistent. but I agree that textfile looks a bit better. how about "opentextfile" ? ;-) </F>