What's correct Python syntax?

Terry Reedy tjreedy at udel.edu
Tue Jan 14 17:05:22 EST 2014


On 1/14/2014 3:46 AM, Igor Korot wrote:
> Hi, ALL,
> I'm trying to process a file which has following lines:
>
> 192.168.1.6 > 192.168.1.7: ICMP echo request, id 100, seq 200, length 30

> However, I don't need all the protocol info. All I'm interested in is
> the last field, which is length.

To directly extract only the needed info:

 >>> s="192.168.1.6 > 192.168.1.7: ICMP echo request, id 100, seq 200, 
length 30"
 >>> s[s.rindex(' ')+1:]
'30'

-- 
Terry Jan Reedy




More information about the Python-list mailing list