I have a debug logging method in my program that just prints the passed in string to sys.stderr if debug is True:
def debug_log(str):
if debug:
print(str, file=sys.stderr)
However, I'm currently passing in some f strings containing expressions that would be time-consuming computations once I go from my debugging data set with a few hundred items to my production dataset with a few million items. If I have a line in my code like:
debug_log(f'{sum([author_dict[a].get("count") for a in author_dict.keys()])} count total in author_dict')
am I correct to assume that that sum is going to get computed when I call debug_log, rather than only happening inside debug_log when it goes to actually do the print statement? And if that's the case is there a clean way to set this up so that it doesn't do the computation when debug is False? (Otherwise I'll just comment out the lines where that's going to matter before I run in production)