How do I call the Python's list while debugging?

后端 未结 3 1862
旧时难觅i
旧时难觅i 2020-12-24 04:24

I have the following python code:

values = set([1, 2, 3, 4, 5])
import pdb
pdb.set_trace()

I run the script and I am in the debugging shell

相关标签:
3条回答
  • 2020-12-24 05:01

    Just print it:

    (Pdb) print list(values)
    

    don't foget to add brackets for python3 version

    (Pdb) print(list(values))
    
    0 讨论(0)
  • 2020-12-24 05:19

    Use the exclamation mark ! to escape debugger commands:

    (Pdb) values = set([1, 2, 3, 4, 5])
    (Pdb) list(values)
    *** Error in argument: '(values)'
    (Pdb) !list(values)
    [1, 2, 3, 4, 5]
    
    0 讨论(0)
  • 2020-12-24 05:22

    Thierry,

    Since this data structure is already an sequence it is redundant to specify it as a list. So this will work fine.

    (Pdb) print values
    

    or

    (Pbd) print(values)
    

    if you are using Python3


    Optionally for a nice listing with newlines

    (Pdb) for x in values:  print x
    

    or

    (Pdb) for x in values:  print(x)
    

    for Python3

    0 讨论(0)
提交回复
热议问题