? about file() and open()
aleaxit at yahoo.com
Sun Jan 2 18:14:48 EST 2005
Sean <D.Sean.Morris at gmail.com> wrote:
> Was wondering if there was any difference between these two functions.
>>> open is file
they're two names for the same object. Which isn't a function, btw:
the object, as you see, is a type (besides calling it to instantiate it,
you might inherit from it, etc).
> I have read some text that said file() wasn't introduced until 2.2 and
> that it was synonymous with open(). Does this mean that I should be
> using file() where I used open() before?
According to Guido, you should keep _calling_ 'open' -- that's the name
to which a factory function to be called may be bound in the future if
and when a good way is found to return filelike objects of some other
type depending on circumstances (e.g., one day it might become possible
to open some kinds of URL that way).
You should use 'file' when you're subclassing, or in other situations
where you want to be sure you're naming a type, not a function (few good
cases come to mind, but maybe isinstance is a possible case, although
likely not _good_...;-).
More information about the Python-list