Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #63952
| From | emile <emile@fenx.com> |
|---|---|
| Subject | Re: What's correct Python syntax? |
| Date | 2014-01-14 14:13 -0800 |
| References | <CA+FnnTzDdgnaNtHzBuq8bYFFOjc5RHuaEocqrzqiB7f5LKHMZg@mail.gmail.com> <lb4cap$j3a$1@ger.gmane.org> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.5486.1389737616.18130.python-list@python.org> (permalink) |
On 01/14/2014 02:05 PM, Terry Reedy wrote:
> On 1/14/2014 3:46 AM, 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
>
>> However, I don't need all the protocol info. All I'm interested in is
>> the last field, which is length.
>
> To directly extract only the needed info:
>
> >>> s="192.168.1.6 > 192.168.1.7: ICMP echo request, id 100, seq 200,
> length 30"
> >>> s[s.rindex(' ')+1:]
> '30'
Any particular reason to prefer that over:
>>> s.split()[-1]
'30'
Is it a length of s and speed or rindex over build and toss the list
kind of thing?
Emile
Back to comp.lang.python | Previous | Next | Find similar | Unroll thread
Re: What's correct Python syntax? emile <emile@fenx.com> - 2014-01-14 14:13 -0800
csiph-web