A-M baby
This commit is contained in:
parent
764da6cbbb
commit
db842d013d
19005 changed files with 197040 additions and 7 deletions
34
Task/History-variables/Python/history-variables-1.py
Normal file
34
Task/History-variables/Python/history-variables-1.py
Normal file
|
|
@ -0,0 +1,34 @@
|
|||
import sys
|
||||
|
||||
HIST = {}
|
||||
|
||||
def trace(frame, event, arg):
|
||||
for name,val in frame.f_locals.items():
|
||||
if name not in HIST:
|
||||
HIST[name] = []
|
||||
else:
|
||||
if HIST[name][-1] is val:
|
||||
continue
|
||||
HIST[name].append(val)
|
||||
return trace
|
||||
|
||||
def undo(name):
|
||||
HIST[name].pop(-1)
|
||||
return HIST[name][-1]
|
||||
|
||||
def main():
|
||||
a = 10
|
||||
a = 20
|
||||
|
||||
for i in range(5):
|
||||
c = i
|
||||
|
||||
print "c:", c, "-> undo x3 ->",
|
||||
c = undo('c')
|
||||
c = undo('c')
|
||||
c = undo('c')
|
||||
print c
|
||||
print 'HIST:', HIST
|
||||
|
||||
sys.settrace(trace)
|
||||
main()
|
||||
2
Task/History-variables/Python/history-variables-2.py
Normal file
2
Task/History-variables/Python/history-variables-2.py
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
c: 4 -> undo x3 -> 1
|
||||
HIST: {'a': [10, 20], 'i': [0, 1, 2, 3, 4], 'c': [0, 1], 'name': ['c']}
|
||||
Loading…
Add table
Add a link
Reference in a new issue