什么'***最旧的帧'在ipdb中意味着什么?

Hou*_*ini 6 python python-3.x pdb ipdb

我试图向服务器发出http请求并检查我得到的内容.但是,当我尝试使用HTTPResponse objectwith ipdb,我不断得到*** Oldest frame而且我无法运行我应该能够运行的对象上的任何函数.这是用于获取的代码块和ipdb输出:

代码块:

for acc in sp_lost:
    url = 'http://www.uniprot.org/uniprot/?query=mnemonic%3a'+acc+'+active%3ayes&format=tab&columns=entry%20name'
    u = urllib.request.urlopen(url)
    ipdb.set_trace()
Run Code Online (Sandbox Code Playgroud)

ipdb输出:

ipdb> url
'http://www.uniprot.org/uniprot/?query=mnemonic%3aSPATL_MOUSE+active%3ayes&format=tab&columns=entry%20name'
ipdb> u
*** Oldest frame
ipdb> str(u)
'<http.client.HTTPResponse object at 0xe58e2d0>'
ipdb> type(u)
<class 'http.client.HTTPResponse'>
ipdb> u.url                      
*** Oldest frame
ipdb> u.url()         # <-- unable to run url() on object...?
*** Oldest frame
ipdb> 
Run Code Online (Sandbox Code Playgroud)

这是什么*** Oldest frame意思,我怎样才能将这个对象变成更有用的东西,我可以运行相应的函数?

Mar*_*ers 12

u是遍历堆栈帧的PDB命令.你已经处于"最上层"的框架中.help u会告诉你更多关于它的信息:

u(p)
Move the current frame one level up in the stack trace
(to an older frame).
Run Code Online (Sandbox Code Playgroud)

该命令是密切相关的d(own)w(here):

d(own)
Move the current frame one level down in the stack trace
(to a newer frame).
w(here)
Print a stack trace, with the most recent frame at the bottom.
An arrow indicates the "current frame", which determines the
context of most commands.  'bt' is an alias for this command.
Run Code Online (Sandbox Code Playgroud)

如果要打印变量u,请!在其前面添加一个,以使调试器不将其解释为调试命令:

!u
!u.url
Run Code Online (Sandbox Code Playgroud)

或使用print():

print(u)
Run Code Online (Sandbox Code Playgroud)

help pdb输出:

调试器无法识别的命令被假定为Python语句,并在被调试程序的上下文中执行.Python语句也可以带有感叹号('!')作为前缀.

Oldest frame是程序启动时堆栈中的框架; 它是最古老的; 的Newest frame,堆叠的另一端,是其中的Python正在执行代码,并执行,其中,如果你击中了Python将继续的当前帧c(ontinue)的命令.

一个带递归函数的小演示:

>>> def foo():
...     foo()
... 
>>> import pdb
>>> pdb.run('foo()')
> <string>(1)<module>()
(Pdb) s
--Call--
> <stdin>(1)foo()
(Pdb) s
> <stdin>(2)foo()
(Pdb) s
--Call--
> <stdin>(1)foo()
(Pdb) s
> <stdin>(2)foo()
(Pdb) s
--Call--
> <stdin>(1)foo()
(Pdb) w
  /Users/mj/Development/Libraries/buildout.python/parts/opt/lib/python2.7/bdb.py(400)run()
-> exec cmd in globals, locals
  <string>(1)<module>()
  <stdin>(2)foo()
  <stdin>(2)foo()
> <stdin>(1)foo()
(Pdb) u
> <stdin>(2)foo()
(Pdb) u
> <stdin>(2)foo()
(Pdb) u
> <string>(1)<module>()
(Pdb) u
> /Users/mj/Development/Libraries/buildout.python/parts/opt/lib/python2.7/bdb.py(400)run()
-> exec cmd in globals, locals
(Pdb) u
*** Oldest frame
Run Code Online (Sandbox Code Playgroud)