Skip to content
Advertisement

How to use list() when in an ipdb session?

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?

Advertisement

Answer

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

! overrides all pdb commands.

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

User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement