DO NOT USE file()
aahz at pythoncraft.com
Sat May 20 19:21:35 CEST 2006
In article <mailman.5997.1148104426.27775.python-list at python.org>,
Ben Finney <bignose+hates-spam at benfinney.id.au> wrote:
>"Tim Peters" <tim.peters at gmail.com> 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:
>> <type 'file'>
>> <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 pythoncraft.com) <*> http://www.pythoncraft.com/
"I saw `cout' being shifted "Hello world" times to the left and stopped
right there." --Steve Gonedes
More information about the Python-list