5

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) 
4
  • I ... don't understand it either :-). It feels like a bug to me. Commented Feb 23, 2015 at 3:25
  • This seems like a very interesting problem, but I can't reproduce. Could you provide a MCVE? Commented Feb 23, 2015 at 15:41
  • @Kevin now you have it... Commented Feb 23, 2015 at 17:59
  • The solution from the duplicate would be to run eval("map(lambda z: seq[z], v)", vars())or, if you want something prettier, !import code; code.interact(local=vars()). Commented Feb 23, 2015 at 20:03

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.