lundi 1 octobre 2018

Can there be an object (e.g. a list) instead of a test expression in python 'elif'? [duplicate]

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