'why does yield get skipped when using send method
guests = ["Tim,22",
"Tonya,45",
"Mary,12",
"Ann,32",
"Beth,20",
"Sam,5",
"Manny,76",
"Kenton,15",
"Kenny,27",
"Dixie,46",
"Mallory,32",
"Julian,4",
"Edward,71",
"Rose,65"]
def read_guestlist(file_name):
while True:
for person in guests:
name, age = person.split(",")
new_guest = yield name
if new_guest != None:
new_name, new_age = new_guest.split(",")
name = new_name
yield "This never gets printed"
yield new_name
guestlist = read_guestlist(guests)
counter = 0
for name in guestlist:
if counter == 5:
guestlist.send("Jane,35")
counter += 1
elif counter == 10:
guestlist.send("Pontus,35")
counter += 1
print(name)
counter += 1
if counter > 17:
break
I have been playing around with this code for a while, and each time I have sent a value using send one yield gets skipped. In this case it is the yield: yield "This never gets printed". My question is: why does that particular yield get skipped each time I use send method?
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
