The following simple
example illustrates how to pass parameter data as input to and as
output from a public Python function.
#
# Name: scalarsTest.py
# Purpose: Test Python program for scalar types
#
# Inputs (name) (type)
# inString String
# inBool Boolean
# inLong Long
# inDouble Double
# inDateTime DateTime
# inDate Date
# inTime Time
#
# Outputs (name) (type)
# outString String
# outBool Boolean
# outLong Long
# outDouble Double
# outDateTime DateTime
# outDate Date
# outTime Time
# import the datetime module to perform datetime operations
import datetime
def scalarsTest(inString, inBool, inLong, inDouble, inDateTime, inDate, inTime):
"Output: outString, outBool, outLong, outDouble, outDateTime, outDate, outTime"
if inString == None:
outString = None
else:
# convert the casing of the string input
outString = inString.swapcase()
print ("\n inString=", inString, " outString=", outString)
if inBool == None:
outBool = None
else:
# reverse value of boolean
outBool = not inBool
print ("\n inBool=", inBool, " outBool=", outBool)
if inLong == None:
outLong = None
else:
# add 10 to long
outLong = inLong + 10
print ("\n inLong=", inLong, " outLong=", outLong)
if inDouble == None:
outDouble = None
else:
# add 10.1 to the double
outDouble = inDouble + 10.1
print ("\n inDouble=", inDouble, " outDouble=", outDouble)
if inDateTime == None:
outDateTime = None
else:
# add a day to the datetime object
outDateTime = inDateTime + datetime.timedelta(days=1)
print ("\n inDateTime=", inDateTime, " outDateTime=", outDateTime)
if inDate == None:
outDate = None
else:
# add a week to the date object
outDate = inDate + datetime.timedelta(weeks=1)
print ("\n inDate=", inDate, " outDate=", outDate)
if inTime == None:
outTime = None
else:
# add 30 minutes to the time object
dt = datetime.datetime.combine(datetime.date.today(), inTime)
dt = dt + datetime.timedelta(minutes=30)
outTime = dt.time()
print ("\n inTime=", inTime, " outTime=", outTime)
# return all of our outputs
return outString, outBool, outLong, outDouble, outDateTime, outDate, outTime