Roy Smith:
> But, along those lines, I've often thought that split() needed a way to not
> just limit the number of splits, but to also throw away the extra stuff.
> Getting the first N fields of a string is something I've done often enough
> that refactoring the slicing operation right into the sp
In article <[EMAIL PROTECTED]>,
Peter Otten <[EMAIL PROTECTED]> wrote:
> Roy Smith wrote:
>
> > In article <[EMAIL PROTECTED]>,
> > Peter Otten <[EMAIL PROTECTED]> wrote:
> >
> >> > I might take it one step further, however, and do:
> >> >
> >> >> fields = line.split()[:2]
> >> >>
Roy Smith wrote:
> In article <[EMAIL PROTECTED]>,
> Peter Otten <[EMAIL PROTECTED]> wrote:
>
>> > I might take it one step further, however, and do:
>> >
>> >> fields = line.split()[:2]
>> >> a, b = map(int, fields)
>> >
>> > in fact, I might even get rid of the very generic,
In article
<[EMAIL PROTECTED]>,
[EMAIL PROTECTED] wrote:
> Roy Smith:
> > No reason to limit how many splits get done if you're
> > explicitly going to slice the first two.
>
> You are probably right for this problem, because most lines are 2
> items long, but in scripts that have to process li
In article <[EMAIL PROTECTED]>,
Peter Otten <[EMAIL PROTECTED]> wrote:
> > I might take it one step further, however, and do:
> >
> >> fields = line.split()[:2]
> >> a, b = map(int, fields)
> >
> > in fact, I might even get rid of the very generic, but conceptually
> > overkill,
Roy Smith:
> No reason to limit how many splits get done if you're
> explicitly going to slice the first two.
You are probably right for this problem, because most lines are 2
items long, but in scripts that have to process lines potentially
composed of many parts, setting a max number of parts sp
Roy Smith wrote:
> In article <[EMAIL PROTECTED]>,
> Peter Otten <[EMAIL PROTECTED]> wrote:
>
>> Without them it looks better:
>>
>> import sys
>> for line in sys.stdin:
>> try:
>> a, b = map(int, line.split(None, 2)[:2])
>> except ValueError:
>> pass
>> else:
>>
In article <[EMAIL PROTECTED]>,
Peter Otten <[EMAIL PROTECTED]> wrote:
> Without them it looks better:
>
> import sys
> for line in sys.stdin:
> try:
> a, b = map(int, line.split(None, 2)[:2])
> except ValueError:
> pass
> else:
> if a + b == 42:
>
hofer wrote:
> Something I have to do very often is filtering / transforming line
> based file contents and storing the result in an array or a
> dictionary.
>
> Very often the functionallity exists already in form of a shell script
> with sed / awk / grep , . . .
> and I would like to have the s
On Sep 2, 12:36 pm, hofer <[EMAIL PROTECTED]> wrote:
> Hi,
>
> Something I have to do very often is filtering / transforming line
> based file contents and storing the result in an array or a
> dictionary.
>
> Very often the functionallity exists already in form of a shell script
> with sed / awk /
On Tue, 02 Sep 2008 10:36:50 -0700, hofer wrote:
> sed 's/\.\..*//' \### remove '//' comments | sed 's/#.*//'
Comment does not match the code. Or vice versa. :-)
Untested:
from __future__ import with_statement
from itertools import ifilter, ifilterfalse, imap
def is_junk(line):
line
Hi,
Something I have to do very often is filtering / transforming line
based file contents and storing the result in an array or a
dictionary.
Very often the functionallity exists already in form of a shell script
with sed / awk / grep , . . .
and I would like to have the same implementation in m
12 matches
Mail list logo