Last active
August 29, 2015 14:09
-
-
Save edran/5b4479d882f77ce10663 to your computer and use it in GitHub Desktop.
csv2OSTV formatter.
This file contains hidden or 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
import argparse | |
def break_r(path, number): | |
n = int(number) | |
f = open(path, "r") | |
ls = f.readlines() | |
print(ls) | |
s = [] | |
for l in ls: | |
s.append(l.split(',')) | |
print(s) | |
for i in range(len(s)): | |
s[i][n - 1] = s[i][n - 1][:1] # just in case | |
print(s) | |
final = [] | |
for k in s: | |
a = [] | |
for i in range(1, n+1): | |
st = str(i) | |
if st in k: | |
a.append(k.index(st) + 1) | |
final.append(a) | |
# print final | |
s = "" | |
for e in final: | |
for x in e: | |
s += str(x) | |
s += " " | |
s = s[:-1] | |
s += "\n" | |
# print s | |
g = open(path + ".out", "w+") | |
g.write(s) | |
g.close() | |
f.close() | |
def parse_file(): | |
""" | |
Parses command line and returns path string. | |
Expected `python -f input.txt`. | |
""" | |
parser = argparse.ArgumentParser() | |
parser.add_argument('-f', '--file', | |
dest='file', | |
required=True, | |
help='Path of file to analyse') | |
parser.add_argument('-n', '--number', | |
dest='number', | |
required=True, | |
help='Number of candidates to analyse') | |
args = parser.parse_args() | |
return (args.file, args.number) | |
def main(): | |
path, number = parse_file() | |
break_r(path, number) | |
if __name__ == "__main__": | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment