2013-04-04 85 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()