[Python-talk] Module to massage text file for better output?
hewitt_tech at comcast.net
Sat Jul 14 09:51:46 EDT 2007
Before I go to the trouble of writing a customer report processor I was
wondering if Python has a module that might expedite writing the
program. Specifically I have a file generated by a SQL utility that
creates a large text file with lot's of data aligned in rows/columns.
The problem is that some of the data is aligned in fixed size fields
that are much larger than necessary. What I'd like to have for output is
data in fixed size fields that are more optimal. So for example I
might have a user's name field that is 80 characters wide but the
largest data never exceeds 35 characters. I want the extra characters
gone but still have good alignment to make the report more readable. The
utility also outputs a header line with the names of the fields
underligned. That also should be adjusted to fit better with the data.
Does Python already have something that would do this or should I just
write the program? I suspect by the time I fiddle with the output I'd
probably end up spending 4 or more hours getting something that would do
P.S. If I wrote this program I could probably read the report to EOF
recording the maximum size of each datum for a particular field and then
rewrite the data making it fit the fields better.
More information about the Python-talk