? about file() and open()

S

Sean

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
 
A

Alex Martelli

Sean said:
Was wondering if there was any difference between these two functions.

Not today:
True

they're two names for the same object. Which isn't a function, btw:
<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
 
M

Mark McEahern

Sean said:
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.
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/python-dev/2004-July/045931.html

// m
 
R

Reinhold Birkenfeld

Sean said:
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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,768
Messages
2,569,574
Members
45,048
Latest member
verona

Latest Threads

Top