By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
444,100 Members | 2,495 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 444,100 IT Pros & Developers. It's quick & easy.

? about file() and open()

P: n/a
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

Jul 18 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a
Sean <D.***********@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
Jul 18 '05 #2

P: n/a
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
Jul 18 '05 #3

P: n/a
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
Jul 18 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.