In python pdb I set a breakpoint in code and run my file. It goes into debug mode as usual. I wanted to print the output of a map call. Hence I typed in the following in pdb:
(Pdb) p inp, pos ('abcde', [0, 1, 2]) (Pdb) map(lambda x: inp[x], pos) *** NameError: global name 'inp' is not defined (Pdb) I don't understand the NameError exception in here...what is the correct way to do a map call in pdb?
Update:
Here is an output which may help you reproduce the problem:
$ cat reproduce.py from itertools import combinations def comb(seq, r): n = len(seq) m = range(n) vectors = list(combinations(m, r)) result = [] for v in vectors: result.append( map(lambda x: seq[x], v) ) return result if __name__ == '__main__': r = comb('abcde', 3) import pprint as pp ; pp.pprint(r) $ python -m pdb reproduce.py > /home/deostroll/Public/code/py/reproduce.py(1)<module>() -> from itertools import combinations (Pdb) b 10 Breakpoint 1 at /home/deostroll/Public/code/py/reproduce.py:10 (Pdb) c > /home/deostroll/Public/code/py/reproduce.py(10)comb() -> map(lambda x: seq[x], v) (Pdb) p v, seq ((0, 1, 2), 'abcde') (Pdb) map(lambda z: seq[z], v) *** NameError: global name 'seq' is not defined (Pdb)
eval("map(lambda z: seq[z], v)", vars())or, if you want something prettier,!import code; code.interact(local=vars()).