Skip to content

Instantly share code, notes, and snippets.

@birkin
Created August 27, 2024 19:13
Show Gist options
  • Save birkin/ac10a6999cb0649d1a2cbcaaf1bda2d0 to your computer and use it in GitHub Desktop.
Save birkin/ac10a6999cb0649d1a2cbcaaf1bda2d0 to your computer and use it in GitHub Desktop.
convert two lines of data to tsv
### convert the two rows of data to a tsv file using the python csv module
import csv
original_two_lines = [
['id', 'jacket_id', 'firstname', 'lastname', 'shortID', 'title', 'pub_date', 'image', 'role', 'dept', 'dept2', 'dept3', 'active', 'created_at', 'updated_at'],
['10', '10', 'First', 'Last', 'flast', 'the long title', '2015', 'flast.jpg', 'author', 'Political Science', 'International and Public Affairs', 'y', '', '', '']
]
with open('data.tsv', 'w') as tsvfile:
writer = csv.writer(tsvfile, delimiter='\t')
writer.writerows(original_two_lines)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment