Stripping whitespace

ryan k ryan at
Wed Jan 23 20:57:12 CET 2008

On Jan 23, 2:53 pm, John Machin <sjmac... at> wrote:
> On Jan 24, 6:17 am, ryan k <r... at> wrote:
> > I am taking a database class so I'm not asking for specific answers.
> > Well I have this text tile:
> >
> Uh-huh, "column-aligned" output.
> > And this code:
> [snip]
> > Because the addresses contain spaces, this won't work because there
> > are too many values being unpacked in row's __init__'s for loop. Any
> > suggestions for a better way to parse this file?
> Tedious (and dumb) way:
> field0 = line[start0:end0+1].rstrip()
> field1 = line[start1:end1+1].rstrip()
> etc
> Why dumb: if the column sizes change, you have to suffer the tedium
> again. While your sample appears to pad out each field to some
> predetermined width, some reporting software (e.g. the Query Analyzer
> that comes with MS SQL Server) will tailor the widths to the maximum
> size actually observed in the data in each run of the report ... so
> you write your program based on some tiny test output and next day you
> run it for real and there's a customer whose name is Marmaduke
> Rubberduckovitch-Featherstonehaugh or somesuch and your name is mud.
> Smart way: note that the second line (the one with all the dashes)
> gives you all the information you need to build lists of start and end
> positions.

Thank you for your detailed response Mr. Machin. The teacher *said*
that the columns were supposed to be tab delimited but they aren't. So
yea i will just have to count dashes. Thank you!

More information about the Python-list mailing list