[Tutor] write list to columns

Puneeth Chaganti punchagan at gmail.com
Thu Apr 12 05:03:21 CEST 2012


On Thu, Apr 12, 2012 at 8:01 AM, questions anon
<questions.anon at gmail.com> 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.
> Somehow they only appear as one long row.
> Any feedback will be greatly appreciated.

You will need to write each line of the file separately, with the
formatting you desire for each line.
The following example may help.


A = range(5)
B = range(5, 10)

records = zip(A, B)
output_format = '%s %s'

with open('output.txt', 'w') as f:
    for record in records:
        f.write(output_format %(record))
        f.write('\n')


HTH,
Puneeth


More information about the Tutor mailing list