Answers for "python yield from"

0

python yield from

def readData():
    with open("data.csv") as f:
        yield from f

# if you returned f, it would throw I/O operation on closed file! 
# if you yield from it, it works ok    
reader = readData()
for i in reader:
    print(i)
Posted by: Guest on January-19-2022

Python Answers by Framework

Browse Popular Code Answers by Language