How to suppress all the print info from the Python Script?
<p>Is there an easy way to suppress all the print info from the python script globally ?</p>

<p>Have a scenario where I had put lot of print info in the script for debug purpose, but when the user runs I don't want the script to print all the infos.</p>

<p>So only when I pass a command line argument like debug=1 or something like that, the print needs to provide the info else it shouldn't print. </p>

<p>Tried simply like, </p>

<pre><code>if sys.argv[1]:
  debug=1
else:
  debug=0

if debug:
  print "Enabled debugging" 
</code></pre>

<p>But for this I need to include the if condition everywhere, instead is there any easy way to shutdown the print info globally ? Share in your comments.</p>

<p>Thanks</p>

<p>This is why you should use the built-in <a href="https://docs.python.org/3/library/logging.html" rel="nofollow"><code>logging</code></a> library rather than writing print statements everywhere.</p>

<p>With that, you can call <code>logger.debug()</code> wherever you need to, and configure at application level whether or not the debug logs are actually output.</p>

python python-2.7