7l3KAmp42TDGeii5zd2DP changeset

Changeset343037313465 (b)
ParentNone (a)
ab
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)
...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
--- Revision None
+++ Revision 343037313465
@@ -0,0 +1,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)