Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > ? about file() and open()

Reply
Thread Tools

? about file() and open()

 
 
Sean
Guest
Posts: n/a
 
      01-02-2005
Was wondering if there was any difference between these two functions.
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?

Sean Morris

 
Reply With Quote
 
 
 
 
Alex Martelli
Guest
Posts: n/a
 
      01-02-2005
Sean <(E-Mail Removed)> 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
 
Reply With Quote
 
 
 
 
Mark McEahern
Guest
Posts: n/a
 
      01-02-2005
Sean wrote:

>Was wondering if there was any difference between these two functions.
>
>

None, as shown here:

D:\Python23>python
Python 2.3.4 (#53, May 25 2004, 21:17:02) [MSC v.1200 32 bit (Intel)]
on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> file == open

True
>>>


>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?
>
>

Google is your friend:

http://www.google.com/search?q=file+vs.+open+python

http://mail.python.org/pipermail/pyt...ly/045931.html

// m
 
Reply With Quote
 
Reinhold Birkenfeld
Guest
Posts: n/a
 
      01-03-2005
Sean wrote:
> Was wondering if there was any difference between these two functions.
> 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?


FYI, I submitted a patch to correct the docs:
http://www.python.org/sf/1094011

Reinhold
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
if and and vs if and,and titi VHDL 4 03-11-2007 05:23 AM



Advertisments