In <3be64ca8-d2e7-493a-b4f3-ef114f581...@googlegroups.com> Rff 
<rw...@avnera.com> writes:

> Hi,
> I have a text file. Now it is required to select every other line of that
> text to generate a new text file. I have read through Python grammar, but
> still lack the idea at the beginning of the task. Could you tell me some
> methods to get this?

Initialize a counter variable to zero.  (Or one, depending if you want to
select odd or even lines.)

Each time you read a line from the file, add one to the counter.

If the counter is odd, process the line; otherwise use the 'continue'
statement to start the loop over and read another line.

-- 
John Gordon         Imagine what it must be like for a real medical doctor to
gor...@panix.com    watch 'House', or a real serial killer to watch 'Dexter'.

-- 
https://mail.python.org/mailman/listinfo/python-list

Reply via email to