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 ?
Answers:
Why should i
be an argument when it is a variable?
(Pdb) whatis i
<type 'int'>
and…
(Pdb) args
(Pdb)
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.
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 ?
Why should i
be an argument when it is a variable?
(Pdb) whatis i
<type 'int'>
and…
(Pdb) args
(Pdb)
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.