inspect complex variable in python debugger, like pudb

半世苍凉 提交于 2019-12-22 08:46:56

问题


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?


回答1:


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.




回答2:


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.




回答3:


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




回答4:


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.



来源:https://stackoverflow.com/questions/12426106/inspect-complex-variable-in-python-debugger-like-pudb

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!