Вопрос

How could I inspect complex variable (list, dict, object) value with python debugger, I am new to python, I tried pudb, it looks like when the variable type is complex type, the debugger only show type of the variable, not the value.

Is it possible to inspect value with pudb? or is there any other python debugger can do this?

Это было полезно?

Решение

To see the contents of a complex data type in pudb:

  1. Use the right arrow to move the cursor to the Variables box on the right.

  2. Use the up and down arrows to move the cursor to the variable you're interested in.

  3. Use the backslash '\' to show/hide the contents of the data structure.

Другие советы

print statement for sequence type works fairly in pdb sub console like bellow

>>> import pdb
>>> l=[9,0]
>>> def j():l=[1,2,3]
... 
>>> pdb.run('j()')
> <string>(1)<module>()
(Pdb) continue
>>> pdb.run('j()')
> <string>(1)<module>()
(Pdb) print l
[1, 2, 3]

Some print obj.name statements will work here too for attribute access of object.

You can just get to a python/ipython shell by pressing "!" . Then you can play around with your variables (view them, change them, etc.)

To show the contents of all the variables on the variable list by default you can go to Preferences by pressing Ctrl+P, and under Variable Stringifier select str() or repr() for a Python interpreter-like display of variables.

Otherwise, you can toggle a selected variable in the variable list (which is accessible by Right arrow keyboard key) by pressing s or r for str() and repr() and t to get back to display its type. With a variable set to show its type you can expand its contents in an orderly tree fashion typing '\' (backslash).

If your variable is a global one or you don't see it for some reason you will have to explicitly state that you wish to watch it by hitting n and then type its name.

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top