[英]how to enable or disable many print statements in python with log?
代碼看起來像這樣 - 有很多用於調試的打印。 我想要一些切換 'button' ,一個啟用/禁用這些打印語句的襯墊。 沒有注釋掉/輸入。
#age
if (row['age'] < 25.0):
print()
print('age < 25')
score += -45.0
print('score changed to : %d ' % score)
elif (row['age'] >= 25.0) and (row['age'] < 29.0):
print()
print('25 < age < 29')
score += -22.0
print('score changed to : %d ' % score)
elif (row['age'] >= 29.0) and (row['age'] < 35.0):
print()
print('29 < age < 35')
score += 1.0
print('score changed to : %d ' % score)
elif (row['age'] >= 35.0):
print()
print('age > 35')
score += 19.0
print('score changed to : %d ' % score)
#f27
if (row['f27']== ''):
print()
print('f27 missing found')
score += -18.0
print('score changed to : %d ' % score)
希望下面的代碼能幫到你。
from __future__ import print_function
debug = True
def print(*args, **kwargs):
if(debug):
return __builtin__.print(*args, **kwargs)
上面的代碼將覆蓋內置的打印功能。 如果調試設置為 True 則打印,否則跳過打印。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.