splitting tables

robsom no.mail at no.mail.it
Mon Feb 9 20:25:53 EST 2004


Il Sat, 07 Feb 2004 13:04:05 -0800, Scott David Daniels ha scritto:

> A way to stay reasonably fast is to use split when it works:
> 
>      lengths = 3,4,2,2,2,8,1,8,3,2,4,2,2,2,2,6
>      ...
>      result = line.split()
>      if len(result) != len(lengths):
>          result, pos = [], 0
>          for length in lengths:
>              next = pos + length + 1
>              result.append(line[pos : next].strip())
>              pos = next
>      ...

I think I understand what you mean, but what data type is lenghts?
is it a list or a tuple? In this case there should be the parenthesis,
shouldn't they?
Sorry, I'm really making newbie silly questions :), but I couldn't find
that in my reference manual.
In any case this would work only when all the elements in a column have
the same length, which, as I said, is not always the case. thanks a lot

R



More information about the Python-list mailing list