[Tutor] write list to columns
Alan Gauld
alan.gauld at btinternet.com
Thu Apr 12 09:48:24 CEST 2012
On 12/04/12 03:31, questions anon wrote:
> I am trying to simply write a list of values to txt file in one column.
> I would then like to add another list in a second column.
That's going to be quite awkward to do. Files like to be written one
complete line at a time. The normal approach would be to build up the
table structure in memory and then write the entire table out in one go.
If it won't fit in memory use a simple database like SQLite to build the
table then print that out row by row.
> Somehow they only appear as one long row.
You need to write newlines but you probably also want to use string
formatting to control the amount of space required so that your columns
line up.
HTH
--
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/
More information about the Tutor
mailing list