altering an object as you iterate over it?

Richard Townsend richard at nospam.com
Fri May 19 23:00:34 CEST 2006


On Fri, 19 May 2006 13:36:35 -0700, James Stroud wrote:

> Paul McGuire wrote:
>> Your coding style is a little dated - are you using an old version of
>> Python?  This style is the old-fashioned way:
> [clip]
>> 1. open("xxx") still works - not sure if it's even deprecated or not - but
>> the new style is to use the file class
> 
> 
> Python 2.3.4 (#4, Oct 25 2004, 21:40:10)
> [GCC 3.3.2 (Mandrake Linux 10.0 3.3.2-6mdk)] on linux2
> Type "help", "copyright", "credits" or "license" for more information.
> py> open is file
> True
> 
> James

As part of a discussion on Python-Dev in  2004 about using open() or file()
Guido replied:

> 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."


See: http://mail.python.org/pipermail/python-dev/2004-July/045931.html


-- 
Richard



More information about the Python-list mailing list