Search code examples
pythonpythonw

How to disable print statements conveniently so that pythonw can run?


I have a python script (.py) which runs normally on the console. When I try running the script using pythonw by changing the extension to (.pyw), it stopped working. My guess is that the print statements are causing pythonw to die based on results returned from Google Search.

Is there a convenient way to disable the print statements so that pythonw can run? I have too many print statements in the script. Changing them one by one is not practical, particularly if I want to switch back to using normal python.

Thanks.


Solution

  • create your own print function, say out, and then change all prints to out. the out method can then be changed once to output to console or to a file.