What's correct Python syntax?

Igor Korot ikorot01 at gmail.com
Tue Jan 14 03:46:56 EST 2014


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

(this is the text file out of tcpdump)

Now I can esily split the line twice: once by ':' symbol to separate
address and the protocol information and the second time by ',' to get
information about the protocol.
However, I don't need all the protocol info. All I'm interested in is
the last field, which is length.

Is there a way to write something like this:

for data in f:
     (address,traffic) = string.split(data, ':')
     length = string.split(traffic, ',')[3]

I'm interesred in only one element, so why should care about everything else?
This can be easily done in Perl, but I'm stuck with Python now. ;-)

Thank you.



More information about the Python-list mailing list