[英]removing print statements in python using eclipse or pycharm
I have looked on stackoverflow but didn't find the answer i was looking for. 我已经看过stackoverflow,但是没有找到我想要的答案。 I have a bunch of python files and was using "print" liberally to debug.
我有一堆python文件,并大量使用“打印”进行调试。 Now I want to get rid of every print statement since none of my python files is expected to print anything to stdout (It is a backend code for a web app).
现在,我想摆脱每一个print语句,因为我的python文件都不希望将任何内容打印到stdout(这是Web应用程序的后端代码)。 How do I get rid of my 'print's?
我如何摆脱我的“印刷品”? I could have simply searched 'print' and replace it with "#print" but some of the print statements are multi-line.
我可以简单地搜索“打印”并将其替换为“ #print”,但是某些打印语句是多行的。
Is there a way to do it using Elipse (preferrably) or PyCharm? 有没有一种方法可以使用Elipse(最好)或PyCharm?
Search for every occurrence of print
and replace with: 搜索每次出现的
print
并替换为:
if __debug__: print
When run using Python's -o
(optimize) command line flag, which you can easily do in your production environment, these statements will then be stripped entirely, as if they were never there. 当使用Python的
-o
(优化)命令行标志运行时,您可以在生产环境中轻松地执行该标志,然后将完全剥离这些语句,就像它们从未存在过一样。 They remain in place to help you with debugging when running Python without -o
. 在不使用
-o
情况下运行Python时,它们将保留在原位以帮助您进行调试。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.