I am trying to design a print function dprint
for debugging use. Specifically, this is what I want to achieve:
def func1(a,b,debug=0):
if debug:
print(Something) # print something if debug mode
below is how I design the dprint
def func2(a,b,debug=0):
def dprint(*args):
if debug:
print(*args) # using the local variable `debug` to detect whether is under debug mood
dprint(Something) # print something if debug mode
func2
can work but is not nice since I need to insert the dprint
function into every other function. I wonder if there is a more decent way to achieve this dprint
function.