On Feb 1, 2:40 pm, Bob Greschke [EMAIL PROTECTED] wrote:
This idiom is what I ended up using (a lot it turns out!):
Parts = Line.split(;)
Parts += (x-len(Parts))*[]
where x knows how long the line should be. If the line already has
more parts than x (i.e. [] gets multiplied by a negative
This idiom is what I ended up using (a lot it turns out!):
Parts = Line.split(;)
Parts += (x-len(Parts))*[]
where x knows how long the line should be. If the line already has
more parts than x (i.e. [] gets multiplied by a negative number)
nothing seems to happen which is just fine in this
On Jan 26, 11:07 am, Bob Greschke [EMAIL PROTECTED] wrote:
I'm reading a file that has lines like
bcsn; 100; 1223
bcsn; 101; 1456
bcsn; 103
bcsn; 110; 4567
The problem is the line with only the one semi-colon.
Is there a fancy way to get Parts=Line.split(;)
Duncan Booth:
def nsplit(s, sep, n):
return (s.split(sep) + []*n)[:n]
Another version, longer:
from itertools import repeat
def nsplit(text, sep, n):
nsplit(bcsn; 101; 1456, ;, 3)
['bcsn', ' 101', ' 1456']
nsplit(bcsn; 101, ;, 3)
['bcsn', ' 101', '']
I'm reading a file that has lines like
bcsn; 100; 1223
bcsn; 101; 1456
bcsn; 103
bcsn; 110; 4567
The problem is the line with only the one semi-colon.
Is there a fancy way to get Parts=Line.split(;) to make Parts always
have three items in it, or do I just have
Bob Greschke [EMAIL PROTECTED] wrote:
Is there a fancy way to get Parts=Line.split(;) to make Parts always
have three items in it, or do I just have to check the length of Parts
and loop to add the required missing items (this one would just take
Parts+=[], but there are other types of
On 2007-01-26 11:13:56 -0700, Duncan Booth [EMAIL PROTECTED] said:
Bob Greschke [EMAIL PROTECTED] wrote:
Is there a fancy way to get Parts=Line.split(;) to make Parts always
have three items in it, or do I just have to check the length of Parts
and loop to add the required missing items