Raspberry Pi, Arduino, Sensors and the data they produce

A Python Program Template


This page presents a skeleton or template for Python programs.


The Template

#!/usr/bin/python #********************************************************************** # Program : .py # Date : YYYYMMDD # #********************************************************************** import os import sys import platform import time import datetime from datetime import datetime #********************************************************************** #***** VARIABLES ***** #********************************************************************** progName = os.path.basename(__file__) # Full path of this python script mypath=os.path.abspath(__file__) # Path location only (excluding script name) baseDir=mypath[0:mypath.rfind("/")+1] baseFileName=mypath[mypath.rfind("/")+1:mypath.rfind(".")] #********************************************************************** #***** FUNCTION DECLARATIONS ***** #********************************************************************** #---------------------------------------------------------------------- def myFunction(): print "Entered myFunction()" return; #---------------------------------------------------------------------- # This function accepts a value to be compared with the low and high # values that are also provided. These values are expressed as integers # and if the value (the first parameter) falls between the low and high # values (inclusive), True will be returned, otherwise False. #---------------------------------------------------------------------- def inRange(value, low, high): intVal = int(value) intLow = int(low) intHigh = int(high) if intLow <= intHigh: return intLow <= intVal <= intHigh else: return intLow <= intVal or intVal <= intHigh #---------------------------------------------------------------------- def execute(): while True: print "DO WORK" break return #********************************************************************** #***** M A I N L I N E C O N T R O L L E R ***** #********************************************************************** if __name__ == '__main__': print("+++++++++++++++++++++++++++++++++++") print("%s - Entering Program" % progName) print "Path to program = " + mypath print sys.version_info print "The O/S = " + platform.system() try: execute() finally: print("%s - Exiting Program" % progName) print("+++++++++++++++++++++++++++++++++++") print("") #********************************************************************** #********************************************************************** #***** E N D O F S O U R C E ***** #********************************************************************** #**********************************************************************

That’s it.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: