Skip to content

Instantly share code, notes, and snippets.

@phelrine
Created January 20, 2012 09:19
Show Gist options
  • Save phelrine/1646333 to your computer and use it in GitHub Desktop.
Save phelrine/1646333 to your computer and use it in GitHub Desktop.
#!/usr/bin/env python
import sys
import csv
import os
if __name__ == '__main__':
data = [[i if i == j else 0 for i in range(5)] for j in range(5)]
# => [[0, 0, 0, 0, 0], [0, 1, 0, 0, 0], [0, 0, 2, 0, 0], [0, 0, 0, 3, 0], [0, 0, 0, 0, 4]]
# dialect = 'excel'
# csv.writer(sys.stdout).writerows(data)
csv.writer(sys.stdout, lineterminator = os.linesep).writerows(data)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment