From 5cbcbc45a4bf768a5c63b613c0a27fb71d7b3302 Mon Sep 17 00:00:00 2001 From: Peter Teuben Date: Tue, 22 Aug 2023 10:14:06 -0400 Subject: [PATCH] allow optional argument --- write_problems.py | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/write_problems.py b/write_problems.py index f50675c..5f59f65 100755 --- a/write_problems.py +++ b/write_problems.py @@ -1,9 +1,18 @@ #! /usr/bin/env python +import sys from re import match from aparser import parse_generic as parse import json -file = open('inputs.txt', 'r') +ofile ="athena_problems.json" + +if len(sys.argv) > 1: + ifile = sys.argv[1] +else: + ifile = 'inputs.txt' + +file = open(ifile, 'r') +print("input: ",ifile) line = file.readline() @@ -33,7 +42,8 @@ json_object = json.dumps(dict, indent=3) # Writing to sample.json -with open("athena_problems.json", "w") as outfile: +with open(ofile, "w") as outfile: outfile.write(json_object) -file.close() \ No newline at end of file +file.close() +print("output:",ofile)