Re: ? about file() and open()
From: Alex Martelli (aleaxit_at_yahoo.com)
Date: 01/03/05
- Next message: Mike Meyer: "Re: The Industry choice"
- Previous message: Jonas Galvez: "Re: HTTP GET request with basic authorization?"
- In reply to: Sean: "? about file() and open()"
- Next in thread: Mark McEahern: "Re: ? about file() and open()"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Mon, 3 Jan 2005 00:14:48 +0100
Sean <D.Sean.Morris@gmail.com> wrote:
> Was wondering if there was any difference between these two functions.
Not today:
>>> open is file
True
they're two names for the same object. Which isn't a function, btw:
>>> type(open)
<type 'type'>
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_...;-).
Alex
- Next message: Mike Meyer: "Re: The Industry choice"
- Previous message: Jonas Galvez: "Re: HTTP GET request with basic authorization?"
- In reply to: Sean: "? about file() and open()"
- Next in thread: Mark McEahern: "Re: ? about file() and open()"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|
|