2014-08-27 82 views
2

當我在python中發出warnings.warn()警告時,stderr的輸出不僅包含我的警告方法,還包括來自源代碼的違規行。我想從源代碼中剔除這一行,因爲它確實會減少清楚地表達警告。有誰知道如何做到這一點?Python警告 - 如何不打印源代碼行?

+0

查看警告過濾器 - https://docs.python.org/2/library/warnings.html#the-warnings-filter – shaktimaan 2014-08-27 21:09:02

+2

請參閱[Python:只打印警告信息](http://stackoverflow.com/questions/2187269/python-print-only-the-message-on-warnings) – hlt 2014-08-27 21:09:07

回答