#---------------------------------------------------------------------- # Illustration of the use of global variables, in the context of # writing out HTML Web files. # # Copyright (C) November 8, 2017 -- Dr. William T. Verts # # File handle MyFile is global to both Write and Main, so a change in # either one is seen by the other. This simplifies the writing of # text to a file, as the file handle (and line break) can now never # be forgotten. However, this is a "back-channel" way to # communicate information between functions that doesn't use the # normal mechanisms of the parameter list or the return statement. # Global variables are to be used cautiously, as detrimental side # effects can occur if programmers are careless. #---------------------------------------------------------------------- def Write (S): global MyFile MyFile.write(S + "\n") return def Main(): global MyFile Filename = pickAFolder() + "Test.html" print Filename #---------------------------------------- # Multiline string, for the top of an # HTML Web file. #---------------------------------------- Prologue = """
" + str(I) + " | ") Write ("" + str(math.sqrt(I)) + " | ") Write ("