Hugo Arts wrote:
>> f = open('/etc/passwd', 'r')
> users = f.readlines()
> for user in users:
...
You can iterate over the file directly:
for user in f:
...
The version using readlines() reads the whole file into a list of lines
where the alternative just has to remember the current line.
While it doesn't matter much for small files iterating over the file
directly will save a lot of memory if the input file is large.
Therefore avoiding readlines() is a good habit to get into.
_______________________________________________
Tutor maillist - [email protected]
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor