How to select every other line from a text file?
denismfmcmahon at gmail.com
Tue Oct 14 01:54:09 CEST 2014
On Mon, 13 Oct 2014 10:38:48 -0700, Rff wrote:
> 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?
So this could be written as an algorithm something like:
1/ open the input file
2/ open the output file
3/ while there are lines to read from the input file
3/1/ read a line from the input file
3/2/ if I should output this line
3/2/1/ write line to output file
4/ close the input file
5/ close the output file
Or in several other ways, and once you have an algorithm, you can start
coding it (or implementing it in the programming language of your choice,
whichever form of words best pleases your perfesser).
Denis McMahon, denismfmcmahon at gmail.com
More information about the Python-list