Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #63884
| References | <mailman.5437.1389689219.18130.python-list@python.org> <cfd7f2f1-c8cb-4901-a6d7-630674ab20d4@googlegroups.com> <mailman.5439.1389691509.18130.python-list@python.org> <41a71031-be78-475f-bab2-822e35f909b7@googlegroups.com> |
|---|---|
| Date | 2014-01-14 02:02 -0800 |
| Subject | Re: What's correct Python syntax? |
| From | Igor Korot <ikorot01@gmail.com> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.5443.1389693753.18130.python-list@python.org> (permalink) |
Hi, Rustom,
On Tue, Jan 14, 2014 at 1:37 AM, Rustom Mody <rustompmody@gmail.com> 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 "<stdin>", line 1, in <module>
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
Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll 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