Skip to content

Instantly share code, notes, and snippets.

@podhmo
Created November 28, 2020 03:39
Show Gist options
  • Save podhmo/f6e2c4dc2d645a7c4411c525b8722263 to your computer and use it in GitHub Desktop.
Save podhmo/f6e2c4dc2d645a7c4411c525b8722263 to your computer and use it in GitHub Desktop.
def gen():
yield 1
yield 2
yield 3
def use(gen):
def _use(n):
print(n)
for i in gen:
_use(i)
use(gen())
def gen():
yield 1
yield 2
try:
yield None
except Exception as e:
print("hmm", e)
yield 4 # never
def use(gen):
def _use(n):
print(n + 1)
for i in gen:
try:
_use(i)
except TypeError as e:
gen.throw(e)
use(gen())
def gen():
yield 1
yield 2
try:
yield None
except TypeError as e:
print("hmm", e)
yield 100
yield 5 # ok
def use(gen):
def _use(n):
print(n + 1)
for i in gen:
try:
_use(i)
except TypeError as e:
print("!", gen.throw(e))
use(gen())
def gen():
try:
yield 1
yield 2
yield 3
yield 4 # never
yield 5 # never
except GeneratorExit as e:
print("!?", e)
def use(gen):
def _use(n):
print(n + 1)
for i in gen:
_use(i)
if i == 3:
break
use(gen())
00:
python $(shell echo $@*.py)
01:
python $(shell echo $@*.py)
02:
python $(shell echo $@*.py)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment