Another way to do this is to use iterools.islice
to slice the file object:
>>> from itertools import islice
>>> def yield_alt(f, option='odd'):
if option == 'odd':
return islice(f, 0, None, 2)
return islice(f, 1, None, 2)
...
>>> with open('abc1') as f:
for line in yield_alt(f):
print line,
...
this is a blah
whatever foo bar
>>> with open('abc1') as f:
for line in yield_alt(f, 'even'):
print line,
...
I don't care,
ahaha