Open derwiki opened 13 years ago
options = dict() for arg in sys.argv[1:]: try: key, value = arg.strip().split('=') key = key[2:].replace('-', '_') options[key] = value except ValueError: pass
try: fin = open(options['infile'], 'r') except KeyError: fin = sys.stdin
try: fout = open(options['outfile'], options.get('write_mode', 'w+')) except KeyError: fout = sys.stdout
Ugh, spacing is awful on that last comment. options is a kludge, it needs replaced with argParser or optionParser -- the fin/fout stuff seems pretty clean though.
A lot of the features of json2csv.py would be useful in other scripts. It would be nice to make the marginal cost of a new script to be just the transform function -- to work with stdin/out or --input, --output for free.