We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 64c91fb commit 5159f67Copy full SHA for 5159f67
1 file changed
samples/advance/do_yield.py
@@ -6,12 +6,9 @@ def each_ascii(s):
6
yield ord(ch)
7
return '%s chars' % len(s)
8
9
-def yield_from(g):
10
- try:
11
- while True:
12
- next(g)
13
- except StopIteration as s:
14
- return s.value
+def yield_from(s):
+ r = yield from each_ascii(s)
+ print(r)
15
16
def main():
17
for x in each_ascii('abc'):
@@ -26,6 +23,7 @@ def main():
26
23
# using yield from in main() will change main() from function to generator:
27
24
# r = yield from each_ascii('hello')
28
25
29
- print(yield_from(each_ascii('hello'))) # => '5 chars'
+ for ch in yield_from('hello'):
+ pass
30
31
main()
0 commit comments