Re: ? about file() and open()

From: Alex Martelli (aleaxit_at_yahoo.com)
Date: 01/03/05


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



Relevant Pages

  • Re: now banned..
    ... and then you sent five more calling me names in each one. ... You, Dimwit Dan, JackoffJim from Florida, and Scott sure like to discuss that other place in some detail here. ... BTW, Jim H may not have been the only poster to complain to the moderator about your foul-mouthed little private messages. ...
    (rec.boats)
  • Re: Newbie Autokeys help needed
    ... btw, for proper terminology, what you posted was a procedure, not a ... calling the textboxes controls or not. ... module/public module concept. ...
    (microsoft.public.access.macros)
  • Re: Anybody else having trouble getting a copy of LGWLDtL?
    ... > That's what calling your credit card company is for. ... Was not a company problem but a post office problem (some P.O. Ahole ... Credit Card Company never entered into it! ... BTW if I were you I would not want to use your CC too much especially ...
    (alt.video.dvd)
  • Re: Arjuna: Into the Another World OST ~ Question...
    ... Never mind, I just noticed that the track is included, well, sort of. ... Comparing the import and domestic version's running times of the two ... Great music, BTW! ... Sean ...
    (rec.arts.anime.music)
  • Re: systems microcode p670
    ... btw. my p670 heard you calling it a baby and send me this ... topas-screenshot along with the question: what io are the adults capable ...
    (AIX-L)