Created
November 28, 2020 03:39
-
-
Save podhmo/f6e2c4dc2d645a7c4411c525b8722263 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def gen(): | |
yield 1 | |
yield 2 | |
yield 3 | |
def use(gen): | |
def _use(n): | |
print(n) | |
for i in gen: | |
_use(i) | |
use(gen()) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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()) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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()) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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()) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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