Writing a TSV file

suggest change

Python

import csv

with open('/tmp/output.tsv', 'wt', newline='') as out_file:
    tsv_writer = csv.writer(out_file, delimiter='\t')
    tsv_writer.writerow(['name', 'field'])
    tsv_writer.writerow(['Dijkstra', 'Computer Science'])
    tsv_writer.writerow(['Shelah', 'Math'])
    tsv_writer.writerow(['Aumann', 'Economic Sciences'])

Output file

The writer separates columns with tab characters. On Windows, omit newline='' and the file can contain \r\r\n. The gaps below are how this page shows those tabs:

$ cat /tmp/output.tsv

name    field
Dijkstra    Computer Science
Shelah    Math
Aumann    Economic Sciences

Feedback about page:

Feedback:
Optional: your email if you want me to get back to you:



Table Of Contents