DO NOT USE file()

Aahz aahz at
Sat May 20 19:21:35 CEST 2006

In article <mailman.5997.1148104426.27775.python-list at>,
Ben Finney  <bignose+hates-spam at> wrote:
>"Tim Peters" <tim.peters at> writes:
>> [John Salerno, on the difference between `open` and `file`]
>>> Interesting. What is the difference between them now?
>> In 2.5 `file` is unchanged but `open` becomes a function:
>>>>> file
>> <type 'file'>
>>>>> open
>> <built-in function open>
>In that case I'll happily use 'file()', since it meshes nicely with
>creating a new instance of any built-in type.

Nobody will prevent you from going against the standard decreed by Guido.
But you also probably won't be able to contribute any code to the
standard library, and other people mucking with your code who do care
about Guido's decrees will probably change it.

Unlike all the other built-in types, files are special because they are
proxies for non-Python external objects.  For that reason, there has long
been interest in extending open() to work with file-like objects (such as
URLs).  Splitting open() and file() is a necessary precondition to making
that happen, and it's also possible that Python 3.0 may have separate
textfile and binary file objects.  Finally, file() doesn't exist in
Python 2.1 and earlier, and using file() instead of open() is gratuitous
Aahz (aahz at           <*>

"I saw `cout' being shifted "Hello world" times to the left and stopped
right there."  --Steve Gonedes

More information about the Python-list mailing list