Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #63890

Re: What's correct Python syntax?

From Alister <alister.ware@ntlworld.com>
Subject Re: What's correct Python syntax?
Newsgroups comp.lang.python
References <mailman.5437.1389689219.18130.python-list@python.org>
Message-ID <AM8Bu.26289$Ke3.20337@fx35.am4> (permalink)
Organization virginmedia.com
Date 2014-01-14 10:59 +0000

Show all headers | View raw


On Tue, 14 Jan 2014 00:46:56 -0800, 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
> 
> (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.

Am I missing something obvious here?
just split on ','

field [0] will contain a mix of data but who cares? you don't want it 
anyway (you can always process it again afterwards.

>>> a='192.168.1.6 > 192.168.1.7: ICMP echo request, id 100, seq 200, 
length 30'
>>> data=a.split(',')
>>> data
['192.168.1.6 > 192.168.1.7: ICMP echo request', ' id 100', ' seq 200', ' 
length 30']
>>> data[3]
' length 30'



-- 
It's not against any religion to want to dispose of a pigeon.
		-- Tom Lehrer, "Poisoning Pigeons in the Park"

Back to comp.lang.python | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

What's correct Python syntax? Igor Korot <ikorot01@gmail.com> - 2014-01-14 00:46 -0800
  Re: What's correct Python syntax? Rustom Mody <rustompmody@gmail.com> - 2014-01-14 00:54 -0800
    Re: What's correct Python syntax? Igor Korot <ikorot01@gmail.com> - 2014-01-14 01:25 -0800
      Re: What's correct Python syntax? Rustom Mody <rustompmody@gmail.com> - 2014-01-14 01:37 -0800
        Re: What's correct Python syntax? Igor Korot <ikorot01@gmail.com> - 2014-01-14 02:02 -0800
          Re: What's correct Python syntax? Rustom Mody <rustompmody@gmail.com> - 2014-01-14 02:16 -0800
            Re: What's correct Python syntax? Igor Korot <ikorot01@gmail.com> - 2014-01-14 02:35 -0800
              Re: What's correct Python syntax? Rustom Mody <rustompmody@gmail.com> - 2014-01-14 02:51 -0800
          Re: What's correct Python syntax? Roy Smith <roy@panix.com> - 2014-01-14 08:47 -0500
        Re: What's correct Python syntax? Peter Otten <__peter__@web.de> - 2014-01-14 12:33 +0100
        Re: What's correct Python syntax? Ned Batchelder <ned@nedbatchelder.com> - 2014-01-14 07:19 -0500
        Re: What's correct Python syntax? Dennis Lee Bieber <wlfraed@ix.netcom.com> - 2014-01-14 08:58 -0500
    Re: What's correct Python syntax? Mark Lawrence <breamoreboy@yahoo.co.uk> - 2014-01-14 09:37 +0000
    Fwd: What's correct Python syntax? Igor Korot <ikorot01@gmail.com> - 2014-01-14 02:03 -0800
      Re: Fwd: What's correct Python syntax? Larry Hudson <orgnut@yahoo.com> - 2014-01-14 22:00 -0800
  Re: What's correct Python syntax? Alister <alister.ware@ntlworld.com> - 2014-01-14 10:59 +0000
  Re: What's correct Python syntax? Roy Smith <roy@panix.com> - 2014-01-14 08:34 -0500

csiph-web