[Python-Dev] lifting of prohibition against readlines inside a "for line in file" in Py3?
Mitchell L Model
MLMLists at Comcast.net
Wed Feb 18 18:42:06 CET 2009
In Digest Vol. 67, Issue 52 (13 Feb 2009) I pointed out that Python
2's prohibition against performing readlines on a file being iterated
over appears to have been lifted in Python 3. I asked if this was
intentional and whether it should be add to the "What's New"
documentation. I also expressed muy surprise that "for line in
fil"'s can be nested using the same fil in both Python 2 and 3. I
presented an example for each point and some and further comments.
I didn't get any response. Is this the wrong list for the question?
Did appropriate responders assume another would respond? I want to
reraise this because lifting of that prohibition is a quite
significant change in the behavior from Python 2. Even if it ws a bug
in Python 2, or the side effect of other changes in Python 3, it
should at least be documented prominently. True, no-one's code will
be affected by lifting a prohibition against something their code
couldn't have done, but the new behavior offers significant
flexibility in writing "for line in fil" iterations in that it allows
recognizing the beginning of a sequence of lines that should be
considered a unified "chunk" and allows the loop to do readlines to
handle the rest of the chunk. Some of these can be handled by just
nesting a second "for line in fil" inside a conditional inside the
outer iteration but some are better handled by individual readlines.
I'd appreciate comments -- especially a redirection to a different
list, if this one isn't appropriate for my query.
More information about the Python-Dev
mailing list