open is not obsolete (was Re: understanding self
Colin J. Williams
cjw at sympatico.ca
Thu Jul 8 08:07:30 EDT 2004
More information about the Python-list mailing list
Thu Jul 8 08:07:30 EDT 2004
- Previous message (by thread): Parametrized module import
- Next message (by thread): open is not obsolete (was Re: understanding self
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
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.
- Previous message (by thread): Parametrized module import
- Next message (by thread): open is not obsolete (was Re: understanding self
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
More information about the Python-list mailing list