Path: csiph.com!newsfeed.hal-mli.net!feeder3.hal-mli.net!newsfeed.hal-mli.net!feeder1.hal-mli.net!newsfeed.xs4all.nl!newsfeed4.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.002 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; ';-)': 0.03; 'win32': 0.03; 'subject:Python': 0.06; 'indices': 0.07; 'perl,': 0.07; 'lawrence': 0.09; 'lines:': 0.09; 'python': 0.11; 'jan': 0.12; 'language.': 0.14; "','": 0.16; "':'": 0.16; 'element,': 0.16; 'igor': 0.16; 'integers,': 0.16; 'interpreter,': 0.16; 'length.': 0.16; 'mark,': 0.16; 'tuple': 0.16; 'typeerror:': 0.16; 'language': 0.16; 'wrote:': 0.18; 'all,': 0.19; 'bit': 0.19; 'trying': 0.19; 'split': 0.19; '>>>': 0.22; 'example': 0.22; 'separate': 0.22; 'print': 0.22; 'sorry,': 0.24; 'this:': 0.26; 'second': 0.26; '----------': 0.26; 'asking': 0.27; 'skip:" 20': 0.27; 'header:In-Reply-To:1': 0.27; 'correct': 0.29; '(this': 0.29; 'am,': 0.29; 'field,': 0.30; 'said,': 0.30; 'message- id:@mail.gmail.com': 0.30; "i'm": 0.30; 'url:mailman': 0.30; '"",': 0.31; '>>>>': 0.31; 'info.': 0.31; 'request,': 0.31; 'trivial': 0.31; 'file': 0.32; 'text': 0.33; 'url:python': 0.33; '(most': 0.33; 'date:': 0.34; 'something': 0.35; 'test': 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; 'list': 0.37; 'list.': 0.37; 'easily': 0.37; 'thank': 0.38; 'question,': 0.38; 'to:addr:python-list': 0.38; 'little': 0.38; 'recent': 0.39; 'forwarded': 0.39; 'subject:': 0.39; 'to:addr:python.org': 0.39; 'url:mail': 0.40; 'length': 0.61; 'subject:Fwd': 0.61; 'you.': 0.62; 'address': 0.63; 'information': 0.63; 're:': 0.63; 'such': 0.63; 'field': 0.63; 'our': 0.64; 'more': 0.64; 'hardly': 0.84; '2013,': 0.91; 'directly.': 0.95 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=CCrVMaGXu9wOklFsDwoluz7NGssx1NxZoh0ejOQrB2Y=; b=B6QwH4ehhP9ux7i0DgvHCbR5BwYEXtvrMWR7/kvW7Zo+2hhMEL0YXyuM5ukk5krza5 9rjUAVMGVC7Z0TLh2FaGwsweWWyM52UrpOgsaDhGRCaSrOU+4XM9xJUqzXE3FwisRuBE EUaLDikHNxuVQgl+77UV6wSAjnAGuiGFpw84ZRHJua9pxb+e2GAooCfcJXFhWtTiL2q/ 2XUuRTbMhakC1mlpk6RgsdEDDB8xadAi6jr5hj2m3QTNM03Wuf67KKkyG4KtZJ4ZD4th OrgKV/qwdrnyhl/zTs+mAZfgmF9mjM9v6Zxj5kv62LvHVblZ0WrKAb0FKIO5+izOxETu lWlg== MIME-Version: 1.0 X-Received: by 10.60.51.6 with SMTP id g6mr388944oeo.5.1389693787738; Tue, 14 Jan 2014 02:03:07 -0800 (PST) In-Reply-To: References: Date: Tue, 14 Jan 2014 02:03:07 -0800 Subject: Fwd: 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: 108 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1389693790 news.xs4all.nl 2865 [2001:888:2000:d::a6]:40972 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:63885 Sorry, that was sent to Mark directly. Resending to the list. ---------- Forwarded message ---------- From: Igor Korot Date: Tue, Jan 14, 2014 at 1:50 AM Subject: Re: What's correct Python syntax? To: Mark Lawrence Hi, Mark, On Tue, Jan 14, 2014 at 1:37 AM, Mark Lawrence wrote: > 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. C:\Documents and Settings\Igor.FORDANWORK\Desktop\winpdb>python Python 2.7.5 (default, May 15 2013, 22:43:36) [MSC v.1500 32 bit (Intel)] on win32 Type "help", "copyright", "credits" or "license" for more information. >>> test = "I,like,my,chocolate" >>> print test.split(',')[2,3] Traceback (most recent call last): File "", line 1, in TypeError: list indices must be integers, not tuple Like I said, I'm more used to Perl, but need to work with Python for a moment. Thank you. > > -- > My fellow Pythonistas, ask not what our language can do for you, ask what > you can do for our language. > > Mark Lawrence > > -- > https://mail.python.org/mailman/listinfo/python-list