>>> import dis
>>> def f(x):
... return 1+2+3+4+x
...
>>> f(5)
15
>>> dis.dis(f)
2 0 LOAD_CONST 7 (10)
3 LOAD_FAST 0 (x)
6 BINARY_ADD
This file contains hidden or 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
| """ | |
| A ``send`` function to drive coroutines. | |
| Driving a coroutine that does not yield interesting values: | |
| >>> coro_printer = printer() | |
| >>> _ = send(coro_printer, 10) | |
| got -> 10 | |
| >>> _ = send(coro_printer, 20) |
This file contains hidden or 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 prange(n): | |
| ... for i in range(n): | |
| ... print('->', i) | |
| ... yield i | |
| ... | |
| >>> def f(a, b, c): | |
| ... print((a, b, c)) | |
| ... | |
| >>> f(*prange(3)) | |
| -> 0 |
This file contains hidden or 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
| Double-click LXTerminal and type: | |
| $ idle -n | |
| (the IDLE window appears) | |
| >>> from turtle import * | |
| >>> fd(100) | |
| (a window with a line appears) | |
| How to draw a square: | |
| >>> fd(100) | |
| >>> rt(90) | |
| >>> fd(100) |
This file contains hidden or 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
| class State(object): | |
| def __init__(self, value): | |
| self.value = value | |
| def __repr__(self): | |
| return '%s(%r)' % (self.__class__.__name__, self.value) | |
| def __str__(self): | |
| return state.value |
This file contains hidden or 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
| I am a happy paying customer of Dropbox, but the news that you have | |
| appointed Condoleezza Rice to your board is extremely disturbing and | |
| I will ditch your service if this decision is not reversed. | |
| Dr. Rice defends warrantless wiretapping. How am I supposed to trust | |
| Dropbox with my personal files if your management cannot understand | |
| the implications of this appointment? And if they do understand | |
| -- which may well be the case -- then I am very sorry I ever shared | |
| any of my files with you. |
This file contains hidden or 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
| from random import shuffle | |
| class Tombola(object): | |
| from inplace import pairswap # LR: esse import é desnecessário, e este é um lugar estranho para fazer imports | |
| '''Sorteia itens sem repetir''' | |
| def carregar(self, seq): | |
| self.itens = list(seq) |
This file contains hidden or 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
| from random import shuffle | |
| class Tombola(object): | |
| '''Sorteia itens sem repetir''' | |
| def carregar(self, seq): | |
| self.itens = list(seq) | |
| def misturar(self, pairswap=None): | |
| pairswap(self.itens) if pairswap else shuffle(self.itens) # LR: funciona mas é melhor testar explicitamente arg is None |
This file contains hidden or 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
| from random import shuffle | |
| class Tombola(object): | |
| '''Sorteia itens sem repetir''' | |
| def carregar(self, seq): | |
| self.itens = list(seq) | |
| def misturar(self, misturadora=None): | |
| if misturadora: # LR: isso funciona mas é melhor sempre testar explicitamente argumento is None |