Path: csiph.com!usenet.pasdenom.info!dedibox.gegeweb.org!gegeweb.eu!nntpfeed.proxad.net!proxad.net!feeder1-2.proxad.net!usenet-fr.net!nerim.net!novso.com!newsfeed.xs4all.nl!newsfeed1.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!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.000 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; ';-)': 0.03; 'from:addr:yahoo.co.uk': 0.04; 'subject:Python': 0.06; 'perl,': 0.07; 'lawrence': 0.09; 'lines:': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'python': 0.11; 'jan': 0.12; 'language.': 0.14; "','": 0.16; "':'": 0.16; 'element,': 0.16; 'igor': 0.16; 'interpreter,': 0.16; 'length.': 0.16; 'received:80.91.229.3': 0.16; 'received:plane.gmane.org': 0.16; 'language': 0.16; 'wrote:': 0.18; 'all,': 0.19; 'trying': 0.19; 'split': 0.19; '>>>': 0.22; 'example': 0.22; 'separate': 0.22; 'header:User- Agent:1': 0.23; 'this:': 0.26; 'second': 0.26; 'asking': 0.27; 'header:X-Complaints-To:1': 0.27; 'header:In-Reply-To:1': 0.27; '(this': 0.29; 'am,': 0.29; 'field,': 0.30; "i'm": 0.30; 'url:mailman': 0.30; 'info.': 0.31; 'request,': 0.31; 'trivial': 0.31; 'file': 0.32; 'text': 0.33; 'url:python': 0.33; 'something': 0.35; 'but': 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; 'question,': 0.38; 'to:addr:python-list': 0.38; 'little': 0.38; 'to:addr:python.org': 0.39; 'received:org': 0.40; 'url:mail': 0.40; 'length': 0.61; 'you.': 0.62; 'address': 0.63; 'information': 0.63; 'such': 0.63; 'field': 0.63; 'our': 0.64; 'hardly': 0.84 X-Injected-Via-Gmane: http://gmane.org/ To: python-list@python.org From: Mark Lawrence Subject: Re: What's correct Python syntax? Date: Tue, 14 Jan 2014 09:37:48 +0000 References: Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Gmane-NNTP-Posting-Host: host-78-147-24-106.as13285.net User-Agent: Mozilla/5.0 (Windows NT 6.1; rv:24.0) Gecko/20100101 Thunderbird/24.2.0 In-Reply-To: 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: 63 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1389692261 news.xs4all.nl 2862 [2001:888:2000:d::a6]:54658 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:63882 On 14/01/2014 09:25, Igor Korot wrote: > 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 Please do a little work before asking such a trivial question, it's hardly difficult from the interactive interpreter, particularly when you already have an example to start with. -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence