问题
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