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: 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: References: Date: Tue, 14 Jan 2014 01:25:00 -0800 Subject: Re: What's correct Python syntax? From: Igor Korot 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 List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: 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 Hi, Rustom, On Tue, Jan 14, 2014 at 12:54 AM, Rustom Mody 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