Skip to content

Instantly share code, notes, and snippets.

@gunchev
Last active January 24, 2022 08:59
Show Gist options
  • Save gunchev/53d610f71ca19d0ca17f6624c8f60cd0 to your computer and use it in GitHub Desktop.
Save gunchev/53d610f71ca19d0ca17f6624c8f60cd0 to your computer and use it in GitHub Desktop.
Python CSV with unix line terminators
#!/usr/bin/python
# -*- coding: utf-8 -*-
import csv
def main():
csv.register_dialect('unix', lineterminator='\n', quoting=csv.QUOTE_MINIMAL)
with open('unix.csv', 'w') as csv_file:
csv_writer = csv.writer(csv_file, dialect='unix')
csv_writer.writerow(('test', 'csv', 'with', 'unix', 'line', 'terminators'))
csv_writer.writerow(('in', 'python', '.', 'See', 'you', '!'))
if __name__ == "__main__":
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment