[New-bugs-announce] [issue13510] Clarify that readlines() is not needed to iterate over a file

Peter Otten report at bugs.python.org
Wed Nov 30 18:42:29 CET 2011


New submission from Peter Otten <__peter__ at web.de>:

I've been looking at code on the tutor mailing list for some time, and

for line in file.readlines(): ...

is a common idiom there. I suppose this is because the readlines() method is easily discoverable while the proper way (iterate over the file object directly) is not.

A note added to the readlines() documentation might help:

"""
You don't need the readlines() method to loop over the lines of a file.
for line in file: process(line)
consumes less memory and is often faster.
"""

----------
assignee: docs at python
components: Documentation
messages: 148679
nosy: docs at python, potten
priority: normal
severity: normal
status: open
title: Clarify that readlines() is not needed to iterate over a file
type: feature request

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue13510>
_______________________________________


More information about the New-bugs-announce mailing list