I have columnar data in which a column of data ranges widely in width. I would like to display this data in a monospace font, for easy viewing while additionally retaining the capabilities of parsing that data with common csv handlers.
I am willing to accept that a strip/trim operations may need to be done by the parsing lib and I am not worried about leading/trailing white space being preserved.
How can I write a csv with fixed width data columns? Is this possible with the csv module?
In Open/Libre Office terms, this is called "Fixed column width" in the Export Text File options.
Example
data = [
('Brown Fox Jumps Over', 'Lorem ipsum',),
('The Lazy', 'dolor sit amet,',),
('Dog', 'consectetur adipiscing elit.',),
]
Desired output
"Header 1 ", "Header 2 ",
"Brown Fox Jumps Over", "Lorem ipsum ",
"The Lazy ", "dolor sit amet, ",
"Dog ", "consectetur adipiscing elit.",
Chiefly I'm looking for a tool to scan a dataset for its widest values and format then entire column to that width for all columns because writing one myself inline feels inappropriate.
csvmodule should handle it. If you tried it and it didn't work, post the details.csvas a generic term. What it sounds like he actually wants is a fixed-width file. OTOH, I'm not certain enough based on his question to go in and edit it for clarity. He may actually want a CSV file with fixed-width columns. :-D