Arthur
Arthur

Reputation: 376

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?

Upvotes: 6

Views: 1075

Answers (2)

tmarice
tmarice

Reputation: 498

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

! overrides all pdb commands.

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

Upvotes: 11

Laurent Erignoux
Laurent Erignoux

Reputation: 177

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

Can you try:

ipdb> res = (list) (some_data) 

Upvotes: 2

Related Questions