[Tutor] creating a tab delimited filename
Brian van den Broek
bvande at po-box.mcgill.ca
Mon Mar 14 01:57:57 CET 2005
jrlen balane said unto the world upon 2005-03-13 19:37:
> so for example, i am creating a text file with file.write()
>
> how am i going to make the file a tab-delimited file??? any
> parameters needed???
>
>>> record1 = ['Foo', 'Bar', 'Baz']
>>> record2 = ['Ham', 'Spam', 'Eggs']
>>> records = [record1, record2]
>>> lines = []
>>> for record in records:
... lines.append('\t'.join(record) + '\n')
...
>>> lines
['Foo\tBar\tBaz\n', 'Ham\tSpam\tEggs\n']
>>> output_file = file('c:/output.txt', 'w')
>>> output_file.writelines(lines)
>>> output_file.close()
>>>
HTH,
Brian vdB
More information about the Tutor
mailing list