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


Groups > comp.lang.python > #63878

Re: What's correct Python syntax?

Path csiph.com!usenet.pasdenom.info!news.etla.org!news.stack.nl!newsfeed.xs4all.nl!newsfeed1.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail
Return-Path <ikorot01@gmail.com>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.006
X-Spam-Evidence '*H*': 0.99; '*S*': 0.00; ';-)': 0.03; 'subject:Python': 0.06; 'perl,': 0.07; 'lines:': 0.09; 'python': 0.11; 'jan': 0.12; "','": 0.16; "':'": 0.16; 'element,': 0.16; 'igor': 0.16; 'length.': 0.16; 'wrote:': 0.18; 'all,': 0.19; 'trying': 0.19; 'split': 0.19; 'separate': 0.22; 'this:': 0.26; 'second': 0.26; 'header:In-Reply-To:1': 0.27; '(this': 0.29; 'am,': 0.29; 'field,': 0.30; 'message-id:@mail.gmail.com': 0.30; "i'm": 0.30; 'url:mailman': 0.30; '>>>>': 0.31; 'info.': 0.31; 'request,': 0.31; 'file': 0.32; 'text': 0.33; 'url:python': 0.33; 'something': 0.35; 'but': 0.35; 'received:google.com': 0.35; 'add': 0.35; 'there': 0.35; '14,': 0.36; 'done': 0.36; 'url:listinfo': 0.36; 'subject:?': 0.36; 'hi,': 0.36; 'url:org': 0.36; 'should': 0.36; 'january': 0.37; 'easily': 0.37; 'thank': 0.38; 'to:addr:python-list': 0.38; 'to:addr:python.org': 0.39; 'url:mail': 0.40; 'length': 0.61; 'you.': 0.62; 'address': 0.63; 'information': 0.63; 'field': 0.63
DKIM-Signature v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :content-type; bh=eiVXtrPU6e0/wktxR8WiWmoOM2Hhixm9zynceeJLJfQ=; b=T9C2O/NHTwjqPEdKdz5Ko6pYpMfe+B2vHChERcEayOfZhFHS7eedHxw+bYSpanU7kH +5Zf4OGLtg+t+U5UdJ1UjQFcQSnCtXkdS+PXmLQGVyje0naMGdSdLhVRLFZIVudG5o5o cNWtEkrvGlgoKL4nVYtYs2BraUATGM8z6MqhwUPyrQBdJo2A0yDLx+yfzblfGJY1ZzW3 NaUNhC3fM/oTvVwCqIlxgcZEebXP/Hjp9ina6+apIa3953v5V9XHypOOwPnLvMPT4AxF unMoMSeRirX/YQyFtYYddgXzmZbXJ4B81Pe19lTp7YuED6QTybmqnqSatlYPcKa7fs/r 9dOg==
MIME-Version 1.0
X-Received by 10.182.48.130 with SMTP id l2mr316059obn.44.1389691500788; Tue, 14 Jan 2014 01:25:00 -0800 (PST)
In-Reply-To <cfd7f2f1-c8cb-4901-a6d7-630674ab20d4@googlegroups.com>
References <mailman.5437.1389689219.18130.python-list@python.org> <cfd7f2f1-c8cb-4901-a6d7-630674ab20d4@googlegroups.com>
Date Tue, 14 Jan 2014 01:25:00 -0800
Subject Re: What's correct Python syntax?
From Igor Korot <ikorot01@gmail.com>
To python-list@python.org
Content-Type text/plain; charset=ISO-8859-1
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.15
Precedence list
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <https://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list/>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <https://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.5439.1389691509.18130.python-list@python.org> (permalink)
Lines 51
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1389691509 news.xs4all.nl 2893 [2001:888:2000:d::a6]:48977
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:63878

Show key headers only | View raw


Hi, Rustom,

On Tue, Jan 14, 2014 at 12:54 AM, Rustom Mody <rustompmody@gmail.com> wrote:
> On Tuesday, January 14, 2014 2:16:56 PM UTC+5:30, 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. ;-)
>
>
>>>> data="192.168.1.6 > 192.168.1.7: ICMP echo request, id 100, seq 200, length 30"
>>>> (add,traff) = data.split(':')
>>>> add
> '192.168.1.6 > 192.168.1.7'
>>>> traff
> ' ICMP echo request, id 100, seq 200, length 30'
>>>> lenn = traff.split(',')
>>>> lenn = traff.split(',')[3]
>>>> lenn
> ' length 30'

What if I want field 2 and field 3? ("seq 200" and "length 30")

Thank you.

>>>>
> --
> https://mail.python.org/mailman/listinfo/python-list

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