P
Paul Rubin
I have a file with contents like:
Vegetable:
spinach
Fruit:
banana
Flower:
Daisy
Fruit:
pear
I want to print out the names of all the fruits. Is the following valid?
f = open(filename)
for line in f:
if line == 'Fruit:\n':
print f.readline()
The issue here is that the sequence has been mutated inside the loop.
If the above isn't good, anyone have a favorite alternative to doing
it like that?
Thanks.
Vegetable:
spinach
Fruit:
banana
Flower:
Daisy
Fruit:
pear
I want to print out the names of all the fruits. Is the following valid?
f = open(filename)
for line in f:
if line == 'Fruit:\n':
print f.readline()
The issue here is that the sequence has been mutated inside the loop.
If the above isn't good, anyone have a favorite alternative to doing
it like that?
Thanks.