-
-
Save phanthaihuan/d2f365d10158469360080b1f412d1691 to your computer and use it in GitHub Desktop.
General python program template
This file contains 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 | |
import sys,os | |
import time | |
import argparse | |
import matplotlib as mpl | |
mpl.use('Agg') | |
import matplotlib.pyplot as plt | |
import numpy as np | |
import networkx as nx | |
def doArgs(argList, name): | |
parser = argparse.ArgumentParser(description=name) | |
parser.add_argument('-v', "--verbose", action="store_true", help="Enable verbose debugging", default=False) | |
parser.add_argument('--input', action="store", dest="inputFn", type=str, help="Input file name", required=True) | |
parser.add_argument('--output', action="store", dest="outputFn", type=str, help="Output file name", required=True) | |
return parser.parse_args(argList) | |
def main(): | |
progName = "Template" | |
args = doArgs(sys.argv[1:], progName) | |
verbose = args.verbose | |
inputFn = args.inputFn | |
outputFn = args.outputFn | |
print "Starting %s" % (progName) | |
startTime = float(time.time()) | |
if not os.path.isfile(inputFn): | |
print "Input doesn't exist, exiting" | |
return | |
outputBase = os.path.dirname(outputFn) | |
if outputBase!='' and not os.path.exists(outputBase): | |
print "Output directory doesn't exist, making output dirs: %s" % (outputBase) | |
os.makedirs(outputBase) | |
print "Finished in %0.4f seconds" % (time.time() - startTime) | |
return | |
if __name__ == '__main__': | |
#sys.argv = ["programName.py","--input","test.txt","--output","tmp/test.txt"] | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment