Created
November 12, 2014 17:52
-
-
Save leafstorm/ae9a159674e47d693f68 to your computer and use it in GitHub Desktop.
Python script for decoding NCSBE voter data
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python3 | |
""" | |
streamncv.py | |
============ | |
Translates from latin-1 tab-separated-values to UTF-8 comma-separated values | |
on the fly, without trying to allocate the entire file. | |
It also prints progress updates. | |
""" | |
import csv | |
import io | |
import sys | |
latin1stdin = io.TextIOWrapper(sys.stdin.buffer, 'latin1') | |
reader = csv.reader(latin1stdin, dialect='excel-tab') | |
writer = csv.writer(sys.stdout, dialect='excel') | |
n = 0 | |
for row in reader: | |
writer.writerow([c.strip() for c in row]) | |
n += 1 | |
if n % 1000 == 0: | |
sys.stderr.write("\r{}".format(n)) | |
sys.stderr.flush() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment