|
|
|
|
|
by m463
2527 days 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')
|
|