pdb – No arguments printed using 'args'

Question:

Code:

import pdb

def fun():
    i = 100
    pdb.set_trace()

if __name__ == '__main__':
    fun()

Output:

$ python pdb_script.py
--Return--
> /home/h/CARDIO/WorkSpace/PDB/pdb_script.py(7)fun()->None
-> pdb.set_trace()
(Pdb) a
(Pdb) a
(Pdb) 

Shouldn’t i be an argument ?

Asked By: CDT

||

Answers:

Why should i be an argument when it is a variable?

(Pdb) whatis i
<type 'int'>

and…

(Pdb) args
(Pdb) 
Answered By: Inbar Rose

A way to accomplish this in Python 3 is by using the following line in pdb:

{k: v for k,v in locals().items() if '__' not in k and 'pdb' not in k}

This will display all the local variables in a dictionary format, less the dunder (i.e. ‘__main__’) and pdb derived ones.

Answered By: Vigilos
Categories: questions Tags: ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.