Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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:

(pdb) list(values) *** Error in argument: '(values)' (Pdb) 

How can I call list(values) in the debugger without invoking the debugger's own list command?

like image 723
Thierry Lam Avatar asked Apr 25 '12 15:04

Thierry Lam


People also ask

How do you debug Python code in Python?

If you're only interested in debugging a Python script, the simplest way is to select the down-arrow next to the run button on the editor and select Debug Python File in Terminal.

How do I run a Python script in debug mode from command line?

Directly use command python pdg-debug.py without -m pdb to run the code. The program will automatically break at the position of pdb. set_trace() and enter the pdb debugging environment. You can use the command p variable to view the variables or use the command c to continue to run.

How does Python debugging work?

Python has a built-in debugger called pdb . It's a simple utility with a command line interface that does the main job. It has all the debugger features you'll need, but if you're looking to pimp it up a little, you can extend it using ipdb, which will provide the debugger with features from IPython.


2 Answers

Just print it:

(Pdb) print list(values) 

don't foget to add brackets for python3 version

(Pdb) print(list(values)) 
like image 160
Fred Foo Avatar answered Oct 11 '22 11:10

Fred Foo


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] 
like image 33
elmotec Avatar answered Oct 11 '22 13:10

elmotec