I am new so I hope this isn't redundant. Lets say I have an input file named "mccell" that looks like
Initial Molecules: 47
Initial Molecules: 1
1 47
1 1
2 48
2 0
3 48
3 0
4 48
4 0
5 48
5 0
6 48
6 0
7 48
7 0
8 48
8 0
9 48
9 0
I am trying to figure out how I would go about printing specific lines in increments that I specify. For example, how would I start at the line "Initial Molecule" and print ONLY the lines that are in increments of two after. To illustrate what I am describing what I want the code to do:
Initial Molecules: 47
1 47
2 48
3 48
4 48
5 48
6 48
7 48
8 48
9 48
I have tried the readlines() function, but to no avail as I can only print the entire file. This is the incorrect code that I have:
fo = open("mccell")
lines = fo.readlines()
print lines
Any help or tips would be appreciated. Thanks!
You can use a counter to keep track of the odd and even lines.