updated from Atlas
This commit is contained in:
26
attic/control/guido/guido0.py
Normal file
26
attic/control/guido/guido0.py
Normal file
@@ -0,0 +1,26 @@
|
||||
"""
|
||||
Exemplo adaptado da mensagem do Guido van Rossum em:
|
||||
https://groups.google.com/forum/#!msg/python-tulip/bmphRrryuFk/aB45sEJUomYJ
|
||||
http://bit.ly/yieldfrom
|
||||
|
||||
>>> principal(ger1())
|
||||
OK
|
||||
42
|
||||
|
||||
Visualização no PythonTutor: http://goo.gl/FQWq2F
|
||||
|
||||
"""
|
||||
|
||||
def ger1():
|
||||
val = yield 'OK'
|
||||
print(val)
|
||||
yield # para evitar o StopIteration
|
||||
|
||||
def principal(g):
|
||||
print(next(g))
|
||||
g.send(42)
|
||||
|
||||
|
||||
# auto-teste
|
||||
import doctest
|
||||
doctest.testmod()
|
||||
29
attic/control/guido/guido1.py
Normal file
29
attic/control/guido/guido1.py
Normal file
@@ -0,0 +1,29 @@
|
||||
"""
|
||||
Exemplo adaptado da mensagem do Guido van Rossum em:
|
||||
https://groups.google.com/forum/#!msg/python-tulip/bmphRrryuFk/aB45sEJUomYJ
|
||||
http://bit.ly/yieldfrom
|
||||
|
||||
>>> principal(ger2())
|
||||
OK
|
||||
42
|
||||
|
||||
Visualização no PythonTutor: http://goo.gl/pWrlkm
|
||||
|
||||
"""
|
||||
|
||||
def ger1():
|
||||
val = yield 'OK'
|
||||
print(val)
|
||||
yield # para evitar o StopIteration
|
||||
|
||||
def ger2():
|
||||
yield from ger1()
|
||||
|
||||
def principal(g):
|
||||
print(next(g))
|
||||
g.send(42)
|
||||
|
||||
|
||||
# auto-teste
|
||||
import doctest
|
||||
doctest.testmod()
|
||||
30
attic/control/guido/guido1b.py
Normal file
30
attic/control/guido/guido1b.py
Normal file
@@ -0,0 +1,30 @@
|
||||
"""
|
||||
Exemplo adaptado da mensagem do Guido van Rossum em:
|
||||
https://groups.google.com/forum/#!msg/python-tulip/bmphRrryuFk/aB45sEJUomYJ
|
||||
http://bit.ly/yieldfrom
|
||||
|
||||
>>> principal(ger2())
|
||||
OK
|
||||
None
|
||||
|
||||
Visualização no PythonTutor: http://goo.gl/61CUcA
|
||||
|
||||
"""
|
||||
|
||||
def ger1():
|
||||
val = yield 'OK'
|
||||
print(val)
|
||||
yield # para evitar o StopIteration
|
||||
|
||||
def ger2():
|
||||
for i in ger1():
|
||||
yield i
|
||||
|
||||
def principal(g):
|
||||
print(next(g))
|
||||
g.send(42)
|
||||
|
||||
|
||||
# auto-teste
|
||||
import doctest
|
||||
doctest.testmod()
|
||||
31
attic/control/guido/guido2.py
Normal file
31
attic/control/guido/guido2.py
Normal file
@@ -0,0 +1,31 @@
|
||||
"""
|
||||
Exemplo adaptado da mensagem do Guido van Rossum em:
|
||||
https://groups.google.com/forum/#!msg/python-tulip/bmphRrryuFk/aB45sEJUomYJ
|
||||
http://bit.ly/yieldfrom
|
||||
|
||||
>>> principal_susto(ger1())
|
||||
OK
|
||||
Bu!
|
||||
|
||||
Visualização no PythonTutor: http://goo.gl/m6p2Bc
|
||||
|
||||
"""
|
||||
|
||||
def ger1():
|
||||
try:
|
||||
val = yield 'OK'
|
||||
except RuntimeError as exc:
|
||||
print(exc)
|
||||
else:
|
||||
print(val)
|
||||
yield # para evitar o StopIteration
|
||||
|
||||
|
||||
def principal_susto(g):
|
||||
print(next(g))
|
||||
g.throw(RuntimeError('Bu!'))
|
||||
|
||||
|
||||
# auto-teste
|
||||
import doctest
|
||||
doctest.testmod()
|
||||
35
attic/control/guido/guido3.py
Normal file
35
attic/control/guido/guido3.py
Normal file
@@ -0,0 +1,35 @@
|
||||
"""
|
||||
Exemplo adaptado da mensagem do Guido van Rossum em:
|
||||
https://groups.google.com/forum/#!msg/python-tulip/bmphRrryuFk/aB45sEJUomYJ
|
||||
http://bit.ly/yieldfrom
|
||||
|
||||
>>> principal_susto(ger2())
|
||||
OK
|
||||
Bu!
|
||||
|
||||
Visualização no PythonTutor: http://goo.gl/QXzQHS
|
||||
|
||||
"""
|
||||
|
||||
def ger1():
|
||||
try:
|
||||
val = yield 'OK'
|
||||
except RuntimeError as exc:
|
||||
print(exc)
|
||||
else:
|
||||
print(val)
|
||||
yield # para evitar o StopIteration
|
||||
|
||||
|
||||
def ger2():
|
||||
yield from ger1()
|
||||
|
||||
|
||||
def principal_susto(g):
|
||||
print(next(g))
|
||||
g.throw(RuntimeError('Bu!'))
|
||||
|
||||
|
||||
# auto-teste
|
||||
import doctest
|
||||
doctest.testmod()
|
||||
Reference in New Issue
Block a user