Path: csiph.com!usenet.pasdenom.info!aioe.org!news.stack.nl!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.004 X-Spam-Evidence: '*H*': 0.99; '*S*': 0.00; 'win32': 0.03; 'subject:Python': 0.06; 'indices': 0.07; 'way:': 0.09; 'python': 0.11; 'jan': 0.12; 'creates': 0.14; 'element,': 0.16; 'expression.': 0.16; 'igor': 0.16; 'index.': 0.16; 'integers,': 0.16; 'irregular': 0.16; 'sliced': 0.16; 'tuple': 0.16; 'tuple,': 0.16; 'typeerror:': 0.16; 'elements': 0.16; 'language': 0.16; 'wrote:': 0.18; 'variable': 0.18; 'bit': 0.19; 'split': 0.19; '>>>': 0.22; 'example': 0.22; 'print': 0.22; 'creating': 0.23; 'sorry,': 0.24; 'mention': 0.26; 'skip:" 20': 0.27; 'values': 0.27; 'header:In-Reply-To:1': 0.27; 'am,': 0.29; 'message- id:@mail.gmail.com': 0.30; "i'm": 0.30; 'url:mailman': 0.30; 'easier': 0.31; 'that.': 0.31; '"",': 0.31; 'perl': 0.31; 'file': 0.32; 'probably': 0.32; 'regular': 0.32; 'url:python': 0.33; '(most': 0.33; 'guess': 0.33; 'not.': 0.33; 'maybe': 0.34; 'could': 0.34; 'test': 0.35; 'but': 0.35; 'received:google.com': 0.35; 'there': 0.35; '14,': 0.36; 'url:listinfo': 0.36; 'doing': 0.36; 'subject:?': 0.36; 'hi,': 0.36; 'url:org': 0.36; 'should': 0.36; 'january': 0.37; 'list': 0.37; 'clear': 0.37; 'thank': 0.38; 'to:addr:python-list': 0.38; 'recent': 0.39; 'does': 0.39; 'to:addr:python.org': 0.39; 'url:mail': 0.40; 'easy': 0.60; 'you.': 0.62; 'field': 0.63; 'soon': 0.63; 'skip:n 10': 0.64; 'more': 0.64; 'world': 0.66; 'between': 0.67; '2013,': 0.91; 'want!': 0.91; 'why?': 0.91 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=/xl7wqn9qKdgmERHc/3vd65L9sq575A+1ybTecz0/JA=; b=UTjgWAq+wlIGJ1EAvUsLNNG5vxvnz/FRI36IPPfIqs2i/XElH1Wm1OEQsekUbEOig3 lfBWDEIqRLQTgMAr9iCIA57+G5PIZ42SgR9vRPJu0TK4uVtBZludu6NS4wBjRGAF24im D8naukaf78aRZ5CFHuAWbZoG1ZVqgM808Yllzm5fGYQw6nEOraDXWi9/ymNdKS2zI9f+ p8GutyDogHXwyUrTHgzOpGtVVbItPA8EVIbH6PRjZBk0gEFRpcKXP6n5iaLmyCgDqehL hNtRUHa1rmtvcSwNsJ6tGUlMoLmkNaevPzSTjIbysY6ksswskOgpRkvZO1UEaC/IEc/D C7uQ== MIME-Version: 1.0 X-Received: by 10.182.43.161 with SMTP id x1mr380010obl.5.1389693744094; Tue, 14 Jan 2014 02:02:24 -0800 (PST) In-Reply-To: <41a71031-be78-475f-bab2-822e35f909b7@googlegroups.com> References: <41a71031-be78-475f-bab2-822e35f909b7@googlegroups.com> Date: Tue, 14 Jan 2014 02:02:24 -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: 58 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1389693753 news.xs4all.nl 2854 [2001:888:2000:d::a6]:40203 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:63884 Hi, Rustom, On Tue, Jan 14, 2014 at 1:37 AM, Rustom Mody wrote: > On Tuesday, January 14, 2014 2:55:00 PM UTC+5:30, Igor Korot wrote: >> >> What if I want field 2 and field 3? ("seq 200" and "length 30") > > Wee you did say: > >> I'm interesred in only one element, so why should care about everything else? > > So its not clear what you want! Sorry, I thought it would be easier to ask this way. Guess not. I am actually looking for a way to get a result from split which is sliced the way I want. Like in my example above. I mean I can probably make more variable by creating a tuple, but why? What is the purpose if I want only couple elements out of split. Doing it Perl way does not help: 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 I can do it this way: >>> testlist = test.split(',') >>> print testlist[2] my but it will needlessly creates a list on which I will access by the index. Why? All I need is couple of values out of n-dimensional list (array). > > Do you want a one-liner? You could use a regular expression. > [You will very soon find that the world divides between the regular and the > irregular folks!] > > Or you want some other perl-ism? You need to say what... Well is there a Python way to do what I want? I mention Perl only because I'm familiar with the language and this is easy in it to do that. Thank you. > > Or maybe you just want to use scapy instead of tcpdump? > -- > https://mail.python.org/mailman/listinfo/python-list