samedi 9 juillet 2016

How do I read two lines from a file at a time using python


I am coding a python script that parses a text file. The format of this text file is such that each element in the file uses two lines and for convenience I would like to read both lines before parsing. Can this be done in Python?

I would like to some something like:

f = open(filename, "r")
for line in f:
    line1 = line
    line2 = f.readline()

f.close

But this breaks saying that:

ValueError: Mixing iteration and read methods would lose data

Related:


Aucun commentaire:

Enregistrer un commentaire