22 lines
598 B
Python
Executable file
22 lines
598 B
Python
Executable file
#! /usr/bin/python3
|
|
# Run as ./util filename expected-number-of-fields
|
|
|
|
|
|
import filemanip
|
|
import sys
|
|
|
|
if len(sys.argv) < 3:
|
|
raise ValueError("need a filename and expected number of fields")
|
|
|
|
# Ternary operator
|
|
# C: condition ? expr-if-true : expr-if-false
|
|
# Python: expr-if-true if condition else expr-if-false
|
|
|
|
vault = filemanip.FileStorage("csv", sys.argv[1])
|
|
expected = int(sys.argv[2])
|
|
recs = vault.load()
|
|
lineno = 1
|
|
for rec in recs:
|
|
print("line {0}: {1} fields; line is {2}".format(lineno, len(rec.fields),
|
|
"faulty" if len(rec.fields) != expected else "fine"))
|
|
lineno += 1
|