Last active
March 1, 2017 12:12
-
-
Save wookietreiber/73337166706b4684cd9e2a6835aee050 to your computer and use it in GitHub Desktop.
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/env python | |
from argparse import ArgumentParser, FileType | |
# ------------------------------------------------------------------------------ | |
# defaults | |
# ------------------------------------------------------------------------------ | |
default_nthreads = 1 | |
default_verbose = False | |
# ------------------------------------------------------------------------------ | |
# parsing arguments | |
# ------------------------------------------------------------------------------ | |
parser = ArgumentParser( | |
description = 'awesome python script', | |
epilog = "use with caution, the awesomeness might slap you in the face!" | |
) | |
parser.add_argument("input", help = "path to input file", type = FileType('r')) | |
parser.add_argument("output", help = "path to output file", type = FileType('w')) | |
parser.add_argument( | |
"-t", "--threads", | |
help = "number of threads to use, defaults to " + str(default_nthreads), | |
dest = "nthreads", | |
default = default_nthreads, | |
metavar = 4 | |
) | |
parser.add_argument( | |
"-v", "--verbose", | |
help = "print more output on what's happening", | |
action = 'store_true', | |
default = default_verbose | |
) | |
options = parser.parse_args() | |
# ------------------------------------------------------------------------------ | |
# assign a few shortcuts | |
# ------------------------------------------------------------------------------ | |
verbose = options.verbose | |
input_file = options.input | |
output_file = options.output | |
# ------------------------------------------------------------------------------ | |
# actual program | |
# ------------------------------------------------------------------------------ | |
if verbose: | |
print("[info] listing options now ...") | |
print("number of threads: {}".format(options.nthreads)) | |
print("input: {}".format(input_file.name)) | |
print("output: {}".format(output_file.name)) | |
if verbose: | |
print("[info] end of script") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment