This question already has an answer here:
def lines(file): # a text file
for line in file:yield line
yield "\n"
def blocks(file):
block=[]
for line in lines(file):
if not line.isspace():
block.append(line)
elif block: #a list in elif test expression
yield ''.join(block).strip()
Aucun commentaire:
Enregistrer un commentaire