4

In a Python 3.5.2 script where I have, e.g.,

import ipdb
ipdb.set_trace()

The interpreter hits these lines and drops me into an ipdb session. Understandably, ipdb has limited functionality compared to an iPython interpreter session (e.g., no magic commands). However, I'm surprised to find that some Python built-ins don't work, namely list().

ipdb> some_data                                                                                                                                               
<zip object at 0x7f416e820388>
ipdb> list(some_data)                                                                                                                                         
*** Error in argument: '(some_data)'
ipdb> list([])                                                                                                                                                
*** Error in argument: '([])'

I'm guessing there is a name collision between the built-in function list() and one of the ipdb commands. Any way around this?

Arthur
  • 345
  • 5
  • 12

2 Answers2

8
ipdb> somedata = {'a':1, 'b': 2}
ipdb> !list(somedata.keys())
['a', 'b']

! overrides all pdb commands.

Source: https://github.com/gotcha/ipdb/issues/106:

tmarice
  • 458
  • 4
  • 8
2

in pdb it seems you can use C like convertions. It is probably similar in iPython.

Can you try:

ipdb> res = (list) (some_data) 
  • That's it! The space between `(list)` and `(some_data)` is not necessary. Incidentally, the same syntax works in a regular Python/ IPython session; not sure what the technical name for this is: `(list)([])`. – Arthur Jan 29 '20 at 23:35