Feb-01-2022, 10:58 PM
In a script I'm working on, sometimes I'd like to turn off some of the print statements that are informative, while leaving the true-warning print's on.
Is there a simple way to define a 'myPrint' function that can be globally controlled, and use that for the informative print's (see below)? Obviously this code only works for printing strings, not vars for instance.
Is there a simple way to define a 'myPrint' function that can be globally controlled, and use that for the informative print's (see below)? Obviously this code only works for printing strings, not vars for instance.
global printFlag
def myPrint(s):
global printFlag
if printFlag:
print(s)
printFlag = True
print("low on memory", mem_size) # always prints warning
myPrint("trace-point reached at time", time() ) # prints debug info IF printFlag is True
