Created
January 10, 2015 17:25
-
-
Save NelsonMinar/f67a5900c9e81d2c111d to your computer and use it in GitHub Desktop.
Quickie script to check an OpenAddresses source CSV file for a consistent number of rows
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 | |
"""Check a CSV source for consistent number of rows | |
Usage: checkCsv.py encoding filename""" | |
import sys | |
counts = {} | |
fp = open(sys.argv[2], encoding=sys.argv[1]) | |
for l in fp: | |
n = len(l.split(',')) | |
counts[n] = counts.get(n, 0) + 1 | |
if len(counts.keys()) == 1: | |
print("All rows in file have %s columns" % list(counts.keys())[0]) | |
else: | |
print("Rows have an inconsistent number of columns") | |
for k in sorted(list(counts.keys())): | |
print(" %3d %7d" % (k, counts[k])) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment