[[python_wiki:python_template]]

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

python_wiki:python_template [2019/05/26 03:50] (current)
Line 1: Line 1:
 +====== Python Template ======
 +
 +**General Information**
 +
 +Start your script/​program using this Python skeleton template. ​
 +
 +----
 +
 +====== Usage ======
 +
 +Instructions here.
 +<code bash>
 +./​python-template.py -h
 +</​code>​
 +
 +----
 +
 +====== The Code ======
 +
 +<code python python-template.py>​
 +#​!/​usr/​bin/​python
 +## Title:
 +## Description:​
 +## Author:
 +## Date:
 +## Recent Changes:
 +
 +#​=======================
 +# Import Modules
 +#​=======================
 +# argparse: Command line arguments
 +import argparse
 +
 +#​=======================
 +# CUSTOMIZE HERE
 +#​=======================
 +# configure any global variables here
 +
 +#​=======================
 +# Get Script Arguments
 +#​=======================
 +# Build argument parser information
 +parser = argparse.ArgumentParser(description="​Put a good program description here."​)
 +parser.add_argument("​-n","​--name",​ help="​This is your name.",​ required=True)
 +parser.add_argument("​-e","​--email",​ help="​Email results.",​ action="​store_true",​ required=False)
 +parser.add_argument("​-t","​--test",​ help="​Do not make changes; perform a test and output details of what would happen.",​ action="​store_true",​ required=False)
 +args = vars(parser.parse_args())
 +
 +# If testing, we don't actually want to do anything
 +if args['​test'​] == True:
 +  print("​-->>​ Test run...no modifications will be made <<​--"​)
 +
 +#​===============================
 +# Functions; Main starts after
 +#​===============================
 +#def my_function():​
 +
 +#​=======================
 +# Main Program Control
 +#​=======================
 +def main():
 +  # Do some stuff
 +  return 0
 +## End of Main ##
 +
 +#​=======================
 +# Execute Main Program
 +#​=======================
 +if __name__ == "​__main__":​
 +  main()
 +</​code>​
 +
 +----
  
  • python_wiki/python_template.txt
  • Last modified: 2019/05/26 03:50
  • (external edit)