2013-07-18 5 views
5

私はサーバーにhttpリクエストを行い、返されたコンテンツを調べようとしています。しかし、私はHTTPResponse objectipdbで掘り下げようとすると、*** Oldest frameを取得し続け、実行できるはずのオブジェクトの機能を実行できません。ここでフェッチにやってコードのブロック、および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出力:*** Oldest frameどういう意味

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> 

、およびどのように私はこのオブジェクトを私が適切な機能を実行することができるより有用なものにすることができますか?

答えて

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()

help pdb出力から
print(u) 

コマンドデバッガは、Python 文であると仮定される認識せず、コンテキスト内で実行されていることプログラムのうち がデバッグされています。 Pythonステートメントの先頭には、感嘆符 ( '!')を付けることもできます。

Oldest frameは、プログラムが開始されたスタック内のフレームです。それは時間の中で最も古いものです。スタックのもう一方の端であるNewest 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

関連する問題