2013-04-04 47 views
1

此行status_msg = res.read()得到一個狀態消息...丟棄標題()狀態文本

some heading|more headings|even more heading 
0|OK|eb725f96b4b094d5f8318741cc1a545f-2 

不過,我想STATUS_MSG丟棄文本(標題)的第一線,只得到第二行行從0開始。

謝謝。

res = urllib.urlopen(self.base_url, data) 
status_msg = res.read() 

回答

5

使用res.readlines(),它返回s產生的消息的行列表

status_msg = '\n'.join(res.readlines()[1:]) 
2

您可以行拆分:

status_msg = '\n'.join(res.read().splitlines()[1:]) 

甚至:

status_msg = '\n'.join(res.readlines()[1:]) 

或致電.readline()的響應丟棄的第一行:

res.readline() # discard the first line 
status_msg = res.read()