Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #63877

Re: What's correct Python syntax?

References <CA+FnnTzDdgnaNtHzBuq8bYFFOjc5RHuaEocqrzqiB7f5LKHMZg@mail.gmail.com>
Date 2014-01-14 19:58 +1100
Subject Re: What's correct Python syntax?
From Chris Angelico <rosuav@gmail.com>
Newsgroups comp.lang.python
Message-ID <mailman.5438.1389690263.18130.python-list@python.org> (permalink)

Show all headers | 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 | NextNext in thread | Find similar | Unroll thread


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