Fixed length lists from .split()?

Bob Greschke bob at passcal.nmt.edu
Fri Jan 26 13:07:27 EST 2007


I'm reading a file that has lines like

    bcsn; 1000000; 1223
    bcsn; 1000001; 1456
    bcsn; 1000003
    bcsn; 1000010; 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 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 lines in the file that have 
about 10 "fields" that also have this problem)?

Thanks!

Bob




More information about the Python-list mailing list