“SyntaxError: unexpected EOF while parsing” while iterating a dictionary in PDB

允我心安 提交于 2019-12-22 04:08:22

问题


I have a pdb trace set inside a GET request. I want to print all the attributes of the request object. I am trying the following, in pdb:

(Pdb) request
<GET /foo HTTP/1.1>
(Pdb) for d in dir(request):
*** SyntaxError: unexpected EOF while parsing (<stdin>, line 1)

I am sure there is something fundamental I am missing here.


回答1:


You can't enter multi-line statements in pdb. You can use the commands command if the code block is to be executed on a break point, though; help commands for more information.

You can also sometimes collapse a multi-line statement into a single line. For example:

for d in dir(request): print d

In your particular case, though, it seems that either print dir(request) or pp dir(request) would suffice.




回答2:


At the pdb prompt, do the following:

(Pdb) a = [1, 2, 3, 4]
(Pdb) for i in a:
*** SyntaxError: unexpected EOF while parsing (<stdin>, line 1)
(Pdb) import code
(Pdb) code.interact(local=locals())
>>> for i in a:
...     print i
... 
1
2
3
4


来源:https://stackoverflow.com/questions/9777807/syntaxerror-unexpected-eof-while-parsing-while-iterating-a-dictionary-in-pdb

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