Writing a TSV file
suggest changePython
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
Found a mistake? Have a question or improvement idea?
Let me know.
Table Of Contents