Line indexing in Python

seafoid fitzpadj at tcd.ie
Fri Dec 18 10:42:19 EST 2009


Hi Guys,

When python reads in a file, can lines be referred to via an index?

Example:

for line in file:
     if line[0] == '0':
         a.write(line)

This works, however, I am unsure if line[0] refers only to the first line or
the first character in all lines.

Is there an easy way to refer to a line with the first character being a
single letter that you know?

Thanks in advance,
Seafoid.
-- 
View this message in context: http://old.nabble.com/Line-indexing-in-Python-tp26845253p26845253.html
Sent from the Python - python-list mailing list archive at Nabble.com.




More information about the Python-list mailing list