open is not obsolete (was Re: understanding self

Colin J. Williams cjw at sympatico.ca
Thu Jul 8 20:09:44 EDT 2004



Paul Watson wrote:
> "Colin J. Williams" <cjw at sympatico.ca> wrote in message
> news:5OaHc.45662$JG5.971334 at news20.bellglobal.com...
> 
>>
>>Delaney, Timothy C (Timothy) wrote:
>>
>>
>>>Jeff Shannon wrote:
>>>
>>>
>>>
>>>>Okay, perhaps "legacy" is a better term than "obsolete".  In either
>>>>case, it's recommended that it not be used in new code, even if there
>>>>is no current plan to remove it.  Not that the specifics of this case
>>>>are particularly germane to the point I was making...
>>>
>>>
>>>As mentioned by Tony, this is not the case. From python-dev:
>>>
>>>
>>>
>>>>>Then should the following line in the reference be changed?
>>>>>
>>>>>"The file() constructor is new in Python 2.2. The previous spelling,
>>>>>open(), is retained for compatibility, and is an alias for file()."
>>>>>
>>>>>That *strongly* suggests that the preferred spelling is file(), and
>>>>>that open() shouldn't be used for new code.
>>>>
>>>>Oops, yes.  I didn't write that, and it doesn't convey my feelings
>>>>about file() vs. open().  Here's a suggestion for better words:
>>>>
>>>>"The file class is new in Python 2.2.  It represents the type (class)
>>>>of objects returned by the built-in open() function.  Its constructor
>>>>is an alias for open(), but for future and backwards compatibility,
>>>>open() remains preferred."
>>>>
>>>>--Guido van Rossum (home page: http://www.python.org/~guido/)
>>>
>>>
>>>Tim Delaney
>>
>>"file" is analogous to a class constructor, while "open" becomes a
>>factory function for that class, with the same signature.
>>
>>This raises the question as to which is the better way of creating an
>>instance of a class.
>>
>>It seems to me that the constructor is, for simple cass, the better way
>>to go.  It provides one way and avoids the question of "Should I use A
>>or B when there are more than one ways of doing some task.
>>
>>What is the general view?
>>
>>Colin W.
> 
> 
> It would appear that the "General DBFL" view is to use open().
> 
> 
I was seeking some ideas on the relative merits of factory functions vs 
constructors.  We have the DBFL view on the specific case of open versus 
file.

Colin W.




More information about the Python-list mailing list