2
當導入pynotify我總是那些討厭的GTK的警告時:GTK錯誤導入pynotify
** (process:25512): WARNING **: Trying to register gtype 'GMountMountFlags' as enum when in fact it is of type 'GFlags'
** (process:25512): WARNING **: Trying to register gtype 'GDriveStartFlags' as enum when in fact it is of type 'GFlags'
** (process:25512): WARNING **: Trying to register gtype 'GSocketMsgFlags' as enum when in fact it is of type 'GFlags'
的問題是,我不知道如何壓制他們,我想:
>>> import sys
>>> from io import BytesIO
>>> sys.stderr = BytesIO()
>>> sys.stdout = BytesIO()
>>> print 's'
>>> import pynotify
** (process:25512): WARNING **: Trying to register gtype 'GMountMountFlags' as enum when in fact it is of type 'GFlags'
** (process:25512): WARNING **: Trying to register gtype 'GDriveStartFlags' as enum when in fact it is of type 'GFlags'
** (process:25512): WARNING **: Trying to register gtype 'GSocketMsgFlags' as enum when in fact it is of type 'GFlags'
不起作用,我試過的另一件事:
with warnings.catch_warnings():
warnings.simplefilter('error')
import pynotify
這也沒有幫助。
好像GTK的消息在不同的stderr
到達。任何想法如何壓制他們?
尼斯。頂部的文檔字符串仍然說'用suppress_fd(...)'代替'with suppress_output(...)'。另外,如果你把這個東西放在一個模塊中,你需要一行像'from suppress_output import suppress_output'。 – FutureNerd 2014-12-15 19:00:59