2 ms·
I do the same sorts of things for my scripts. I start with my "template" script and fill it out. totally over-engineered for most tasks, but then as the tasks
by m463 7y ago
I do the same sorts of things for my scripts.
I start with my "template" script and fill it out.
totally over-engineered for most tasks, but then as the tasks mature they have a firm foundation.
very simplified example:
#!/usr/bin/python
import sys,os,argparse
parser = argparse.ArgumentParser(argument_default=None)
parser.add_argument('-d', '--debug', action='store_true', help='debug flag')
parser.add_argument('files', nargs='*', default=[], help='files to process')
arg = parser.parse_args()
def die(errmsg,rc=1):
print(errmsg, file=sys.stderr)
sys.exit(rc)
if not arg.files:
die('filename required')