Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #63882
| 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 | <python-python-list@m.gmane.org> |
| 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 <breamoreboy@yahoo.co.uk> |
| Subject | Re: What's correct Python syntax? |
| Date | Tue, 14 Jan 2014 09:37:48 +0000 |
| References | <mailman.5437.1389689219.18130.python-list@python.org> <cfd7f2f1-c8cb-4901-a6d7-630674ab20d4@googlegroups.com> <CA+FnnTzv_uz+V8SLK7_VfPvpiDMEgLyA5NndM3eNjftPCe+s5w@mail.gmail.com> |
| 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 | <CA+FnnTzv_uz+V8SLK7_VfPvpiDMEgLyA5NndM3eNjftPCe+s5w@mail.gmail.com> |
| X-BeenThere | python-list@python.org |
| X-Mailman-Version | 2.1.15 |
| Precedence | list |
| List-Id | General discussion list for the Python programming language <python-list.python.org> |
| List-Unsubscribe | <https://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe> |
| List-Archive | <http://mail.python.org/pipermail/python-list/> |
| List-Post | <mailto:python-list@python.org> |
| List-Help | <mailto:python-list-request@python.org?subject=help> |
| List-Subscribe | <https://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.5442.1389692261.18130.python-list@python.org> (permalink) |
| 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 |
Show key headers only | View raw
On 14/01/2014 09:25, Igor Korot wrote:
> Hi, Rustom,
>
> On Tue, Jan 14, 2014 at 12:54 AM, Rustom Mody <rustompmody@gmail.com> 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
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