Created
April 9, 2016 23:29
-
-
Save fvdnabee/2f2c6cfb40623b91c7738eb0c8bb5cff to your computer and use it in GitHub Desktop.
Google code jam input/output file handling in python
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
#!/usr/bin/python3 | |
# Google code jam input/output file handling, implement process_input for the | |
# problem at hand | |
import argparse | |
def process_input(input): | |
output = 0 | |
return output | |
if __name__ == "__main__": | |
parser = argparse.ArgumentParser(description='Input File.') | |
parser.add_argument('f', metavar='file', help='Input file') | |
args = parser.parse_args() | |
file_name = args.f | |
output_lines = [] | |
with open(file_name) as f: | |
first_input_line = True | |
for input_line in f: | |
if first_input_line: # skip number of test cases | |
first_input_line = False | |
continue | |
input = input_line.strip() | |
output = process_input(input) | |
print("{} -> {}".format(input, output)) | |
output_lines.append(output) | |
# write output file: | |
f = open('output', 'w') | |
i = 1 | |
for l in output_lines: | |
f.write("Case #{}: {}\n".format(i, l)) | |
i += 1 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment