? about file() and open()

Discussion in 'Python' started by Sean, Jan 2, 2005.

  1. Sean

    Sean Guest

    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
    Sean, Jan 2, 2005
    #1
    1. Advertising

  2. Sean <> 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
    Alex Martelli, Jan 2, 2005
    #2
    1. Advertising

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

    // m
    Mark McEahern, Jan 2, 2005
    #3
  4. 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
    Reinhold Birkenfeld, Jan 3, 2005
    #4
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. THY
    Replies:
    4
    Views:
    508
    Gönen EREN
    Aug 22, 2003
  2. Simon Mullis
    Replies:
    0
    Views:
    611
    Simon Mullis
    Feb 5, 2009
  3. scad
    Replies:
    4
    Views:
    947
    James Kanze
    May 28, 2009
  4. Schüle Daniel

    File::open and File.open

    Schüle Daniel, Oct 23, 2006, in forum: Ruby
    Replies:
    4
    Views:
    187
    Rick DeNatale
    Oct 24, 2006
  5. iMelody Ooo
    Replies:
    5
    Views:
    413
    Charles Calvert
    Oct 21, 2010
Loading...

Share This Page