user7153 user7153 - 1 year ago 89
Python Question

How do you deal with print() once you done with debugging/coding

To python experts:
I put lots of print() to check the value of my variables.
Once I'm done, I need to delete the print(). It quite time-consuming and prompt to human errors.

Would like to learn how do you guys deal with print(). Do you delete it while coding or delete it at the end? Or there is a method to delete it automatically or you don't use print()to check the variable value?

Answer Source

Use logging instead and here is why.
logging module comes with many simple & handy log methods like debug, info, warning, error, critical
ex:- logging.debug(<debug stuff>)
EDIT I am not sure I understood correctly about your need to disable logging once you are done, but if you want to do away with console logging you can try

#logger = logging.getLogger() # this gets the root logger
logger = logging.getLogger('my-logger')
logger.propagate = False
# now if you use logger it will not log to console.
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download