Created
July 5, 2018 01:47
-
-
Save pydsigner/b5a4c65223167412fde5f18453aa7690 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
g = [locals().__setitem__('_x', (yield locals().get('_x', x)) or locals().get('_x', x)) for x in range(10)] | |
# >>> next(g) | |
# 0 | |
# >>> next(g) | |
# 0 | |
# >>> g.send(3) | |
# 3 | |
# >>> next(g) | |
# 3 | |
# >>> next(g) | |
# 3 | |
# >>> g.send(4) | |
# 4 | |
send_writer = lambda filename, max_lines: (lambda next_shim_target: (next_shim_target, next(next_shim_target))[0])((lambda file: [file.write((yield lines_written)) for lines_written in range(max_lines)])(open(filename, 'w'))) | |
# >>> writer = send_writer('x.txt', 1000) | |
# >>> writer.send('lol\n') | |
# 1 | |
# >>> writer.send("please don't do this") | |
# 2 | |
# >>> writer.close() | |
# >>> open('x.txt').read() | |
# "lol\npleasedon't do this" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment