The Zen of Python:
There should be one-- and preferably only one --obvious way to do it.
So either file
or open
should go.
>>> type(file)
<type 'type'>
>>> type(open)
<type 'builtin_function_or_method'>
open
is a function that can return anything. file()
returns only file
objects.
Though it seems open
returns only file
objects on Python 2. And before Python 2.5 file
and open
are the same object.
As @gnibbler suggested in the comments the original reason for the existence of file
might be to use it as the name for base classes.
Also, file()
in principle could return other types as for example int()
did on earlier Python versions:
>>> type(int(2**64)) is long
True
>>> type(int()) is int
True
>>> int is long
False
This answer is very similar to @Ryan's answer.
In addition BDFL said:
"The file class is new in Python 2.2. It represents the type (class)
of objects returned by the built-in open() function. Its constructor
is an alias for open(), but for future and backwards compatibility,
open() remains preferred." (emphasis mine)