Skip to content

Commit 5159f67

Browse files
committed
update yield sample
1 parent 64c91fb commit 5159f67

1 file changed

Lines changed: 5 additions & 7 deletions

File tree

samples/advance/do_yield.py

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,9 @@ def each_ascii(s):
66
yield ord(ch)
77
return '%s chars' % len(s)
88

9-
def yield_from(g):
10-
try:
11-
while True:
12-
next(g)
13-
except StopIteration as s:
14-
return s.value
9+
def yield_from(s):
10+
r = yield from each_ascii(s)
11+
print(r)
1512

1613
def main():
1714
for x in each_ascii('abc'):
@@ -26,6 +23,7 @@ def main():
2623
# using yield from in main() will change main() from function to generator:
2724
# r = yield from each_ascii('hello')
2825

29-
print(yield_from(each_ascii('hello'))) # => '5 chars'
26+
for ch in yield_from('hello'):
27+
pass
3028

3129
main()

0 commit comments

Comments
 (0)