Revision 343037313465 () - Diff

Link to this snippet: https://friendpaste.com/7l3KAmp42TDGeii5zd2DP
Embed:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
# http://www.norvig.com/python-iaq.html
h = [None] # history

class Prompt:
"""
A prompt a history mechanism.
From http://www.norvig.com/python-iaq.html
"""
def __init__(self, prompt='h[%d] >>> '):
self.prompt = prompt

def __str__(self):
try:
if _ not in h: h.append(_)
except NameError:
pass
return self.prompt % len(h)

def __radd__(self, other):
return str(other) + str(self)