Skip to content

Instantly share code, notes, and snippets.

@anmoljagetia
Created April 20, 2016 14:07
Show Gist options
  • Save anmoljagetia/9f286fe6a3269f0392b90bd5df3eba85 to your computer and use it in GitHub Desktop.
Save anmoljagetia/9f286fe6a3269f0392b90bd5df3eba85 to your computer and use it in GitHub Desktop.
Python Argument Parser
import argparse
# Initialize argument parse object
parser = argparse.ArgumentParser(description="There are two flags, -f for fraud prevalence and -p to check prevalence in the output file")
# This would be an argument you could pass in from command line
parser.add_argument("-f", "--fraud", action="store", type = float, default = 0.2, help = "Enter the prevalence as a float, the default value is 0.2")
parser.add_argument("-p", "--prevalence", action="store_true", default = False, help = "use the flag to print the prevalence")
def main() :
inargs = parser.parse_args()
# Get the prevalence from command line
print "Sexy : " ,inargs.fraud, inargs.prevalence
if __name__ == '__main__':
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment