Ex: Vetting Useful Functions TB1

One of the many things I did when updating the general toolbox  to vPro2A was to keep a running script that vetted the syntax of the functions I list in “Useful Module Functions”.  Some of these took a little head scratching but in the code below everything works (on a windows machine) like a charm.  Here it is for you to try for yourself.


#test TB1 Module Functions:
#MATH
import math
x = 10.2
y = 10.5
z = 10.8
shorttup =(x,y,z)
#ceil - smallest integer > variable value
print(math.ceil(x),math.ceil(y), math.ceil(z))
#fsum - floating point sum of an iterable
print(math.fsum(shorttup))
#sqrt - square root
print(math.sqrt(144))
#log
print("natural: ", math.log(100))
print("base 10: ", math.log(100,10))
#constants: pi and e
print(math.pi, math.e)
#factorial
print(math.factorial(7))

#RANDOM
import random
#seed()
random.seed() # used first with seed causes repeatable events
#choice()
myseq=(56,9,1,212,31,42)
print(random.choice(myseq))
print(random.choice(myseq))
print(random.choice(myseq))
#randomint(start,end)
print("randint: ",random.randint(1,100))
#random()
print("random float 0-1: ", random.random())
print("random float 0-1: ", random.random())
print("random float 0-1: ", random.random())
#SYS
import sys
#path
print(sys.path)
#platform
print(sys.platform)

#DATETIME
from datetime import *
#note: import datetime does not work for some functions
dtetoday= date.today()
print("date.today(): ", dtetoday)
dtup = date.timetuple(dtetoday)
print(dtup)
print("datetime.today: ",datetime.today())
print("datetime.now: ",datetime.now())

#TIME
import time
#note: from time import * does not work for some functions
#localtime
mytime= time.localtime()
print("localtime printed by asctime: ",time.asctime(mytime))
print("date.today() time printed by asctime: ", time.asctime(dtup))
#clock
print("time.clock: ",time.clock())
#sleep
print("sleeping 5 seconds - bye")
time.sleep(3)
print("...zzzzz....")
time.sleep(2)
print("all done, back in action")

#CALENDAR
import calendar
mymo = calendar.TextCalendar()
mymo.setfirstweekday(calendar.SUNDAY)
mymo.prmonth(2018, 7)