Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #63877
| Path | csiph.com!usenet.pasdenom.info!aioe.org!news.stack.nl!newsfeed.xs4all.nl!newsfeed4.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail |
|---|---|
| Return-Path | <rosuav@gmail.com> |
| X-Original-To | python-list@python.org |
| Delivered-To | python-list@mail.python.org |
| X-Spam-Status | OK 0.014 |
| X-Spam-Evidence | '*H*': 0.97; '*S*': 0.00; 'string.': 0.05; 'subject:Python': 0.06; 'cc:addr:python-list': 0.11; 'jan': 0.12; 'from:addr:rosuav': 0.16; 'from:name:chris angelico': 0.16; 'helps!': 0.16; 'igor': 0.16; 'integer,': 0.16; 'length.': 0.16; 'throw': 0.16; 'unexpected': 0.16; 'exception': 0.16; 'wrote:': 0.18; 'split': 0.19; 'cc:addr:python.org': 0.22; 'cc:2**0': 0.24; 'this:': 0.26; 'header:In-Reply-To:1': 0.27; 'field,': 0.30; 'message-id:@mail.gmail.com': 0.30; "i'm": 0.30; 'info.': 0.31; 'request,': 0.31; 'know.': 0.32; 'there,': 0.34; 'received:google.com': 0.35; 'there': 0.35; '14,': 0.36; 'subject:?': 0.36; 'two': 0.37; 'whatever': 0.38; 'pm,': 0.38; 'anything': 0.39; 'either': 0.39; 'space': 0.40; 'hope': 0.61; 'length': 0.61; "you're": 0.61; "you'll": 0.62; 'analysis': 0.75; 'safe;': 0.84; 'to:none': 0.92 |
| 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:cc :content-type; bh=PyYhk8lmG4ewuMdFCVKtW45L6S2QOXH20RmIkFJe54M=; b=uA6Ojah/CZPGtGQj8fFwphn+/fxZcr7wGdAkOUOMthjB+c8EIOCCNjxyQxkjirTR7O CWraQilLirjYvG3YPlJjh9+gA3iE94CPWFyzmcQAi/b1h+NyAIizbEqZ+KPfWvMGOX62 2Ignsb0lXCGnMDmCgBIzzEs9cTmexuUvw3YO3RSIs+uYqQC54MxkgHyeIjOa/i4Tcno4 B1o7W3QQkBnsz73xLK2ArtjNBzjjTWXcqWJr7oJqppI5uMIqWE20Qk453oKfgSrJvib9 YXngX9QQwqd9yUf7d5CDj9JqUU1ZgkqWRq3yfSKoLvaB02ip+sLnaYAM+nr2K4QQwqzY gR1g== |
| MIME-Version | 1.0 |
| X-Received | by 10.66.160.2 with SMTP id xg2mr356899pab.23.1389689898016; Tue, 14 Jan 2014 00:58:18 -0800 (PST) |
| In-Reply-To | <CA+FnnTzDdgnaNtHzBuq8bYFFOjc5RHuaEocqrzqiB7f5LKHMZg@mail.gmail.com> |
| References | <CA+FnnTzDdgnaNtHzBuq8bYFFOjc5RHuaEocqrzqiB7f5LKHMZg@mail.gmail.com> |
| Date | Tue, 14 Jan 2014 19:58:17 +1100 |
| Subject | Re: What's correct Python syntax? |
| From | Chris Angelico <rosuav@gmail.com> |
| Cc | "python-list@python.org" <python-list@python.org> |
| Content-Type | text/plain; charset=UTF-8 |
| 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.5438.1389690263.18130.python-list@python.org> (permalink) |
| Lines | 32 |
| NNTP-Posting-Host | 2001:888:2000:d::a6 |
| X-Trace | 1389690263 news.xs4all.nl 2858 [2001:888:2000:d::a6]:34452 |
| X-Complaints-To | abuse@xs4all.nl |
| Xref | csiph.com comp.lang.python:63877 |
Show key headers only | View raw
On Tue, Jan 14, 2014 at 7:46 PM, Igor Korot <ikorot01@gmail.com> wrote:
> 192.168.1.6 > 192.168.1.7: ICMP echo request, id 100, seq 200, length 30
>
> However, I don't need all the protocol info. All I'm interested in is
> the last field, which is length.
You can split on any string. If you're confident that this is the only
instance of the word "length", you can split on that:
for data in f:
# This will throw an exception if there's no " length "
# or if there are two of them. This means you're safe;
# if anything unexpected happens, you'll know.
_, length = data.split(" length ")
# process length
Alternatively, you can split on the space and take just the very last word:
for data in f:
length = data.split(" ")[-1]
# process length
Either way, the length will be a string. If you need it as an integer,
just do this:
length = int(length)
>From there, you can do whatever analysis you need.
Hope that helps!
ChrisA
Back to comp.lang.python | Previous | Next — Next in thread | Find similar | Unroll thread
Re: What's correct Python syntax? Chris Angelico <rosuav@gmail.com> - 2014-01-14 19:58 +1100 Re: What's correct Python syntax? Jussi Piitulainen <jpiitula@ling.helsinki.fi> - 2014-01-14 11:43 +0200
csiph-web