[Python-Dev] file() vs open(), round 7

Fredrik Lundh fredrik at pythonware.com
Tue Dec 27 16:37:36 CET 2005


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>





More information about the Python-Dev mailing list