2013-07-18 56 views
5

我正在嘗試向服務器發出http請求,並檢查我找回的內容。然而,當我嘗試 ipdb,我一直在,我不能運行我應該能夠運行的對象上的任何功能。這裏是代碼做給取塊,和ipdb輸出:'***最古老的框架'在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() 

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> 

什麼的*** Oldest frame平均值,我怎樣才能把這個對象變成更有用的東西,我可以運行適當的功能?

回答

10

u是用於遍歷堆棧幀的PDB命令。你已經在'最上面'的框架中。 help u會告訴你更多關於它:

u(p) 
Move the current frame one level up in the stack trace 
(to an older frame). 

命令密切相關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. 

如果你想打印變量u,前綴它帶有!以使調試器不會將其解釋爲調試命令:

!u 
!u.url 

或使用print()

print(u) 

help pdb輸出:

命令調試器不能識別被認爲是Python的 語句,並在上下文中執行的程序正在調試 。 Python語句也可以加一個感嘆號 ('!')作爲前綴。

Oldest frame是程序啓動的棧中的框架;它是時間最早的;是堆棧的另一端,是Python正在執行代碼的位置,並且是當前執行框架,如果點擊c(ontinue)命令,Python將繼續執行。

一個小的演示用遞歸函數:

>>> 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 
+0

感謝皮特斯先生,翔實和全面的解釋一如既往:) – Houdini