7l3KAmp42TDGeii5zd2DP changeset
Changeset | 343037313465 (b) |
---|---|
Parent | None (a) |
a | b | ||
---|---|---|---|
0 | + | # http://www.norvig.com/python-iaq.html | |
0 | + | h = [None] # history | |
0 | + | ||
0 | + | class Prompt: | |
0 | + | """ | |
0 | + | A prompt a history mechanism. | |
0 | + | From http://www.norvig.com/python-iaq.html | |
0 | + | """ | |
0 | + | def __init__(self, prompt='h[%d] >>> '): | |
0 | + | self.prompt = prompt | |
0 | + | ||
0 | + | def __str__(self): | |
0 | + | try: | |
0 | + | if _ not in h: h.append(_) | |
0 | + | except NameError: | |
0 | + | pass | |
0 | + | return self.prompt % len(h) | |
0 | + | ||
0 | + | def __radd__(self, other): | |
0 | + | return str(other) + str(self) | |
... |
|
|