簡體   English   中英

禁止在Hachoir發出警告

[英]Suppress warnings in Hachoir

我正在使用hachior解析器來捕獲大量視頻文件的持續時間。 (我正在根據文件的時間戳及其持續時間重置“上次修改”日期。)我正在使用根據此問題改編的代碼。

我遇到的問題是hachior為每個文件報告四個警告,這使我的輸出混亂。 我仍然可以從文件中獲取持續時間,因此,如果可能的話,我想知道如何在輸出中禁止顯示這些警告。

Python並不是我真正的強項,因此我不確定在哪里查找,並且hachior的文檔在錯誤報告中似乎很少。 我不希望訴諸於腳本輸出中的行。

編輯:運行python -W ignore set_last_modified.py導致打印相同的[warn]行。

[warn] [/headers/stream[2]/stream_fmt] Can't get field "stream_hdr" from /headers/stream[2]
[warn] [/headers/stream[2]/stream_fmt] [Autofix] Fix parser error: stop parser, add padding
[warn] [/headers/stream[3]/stream_fmt] Can't get field "stream_hdr" from /headers/stream[3]
[warn] [/headers/stream[3]/stream_fmt] [Autofix] Fix parser error: stop parser, add padding

您可以使用-W選項來抑制python中的警告。

python -W ignore my_file.py

編輯:由於您已經嘗試了上述方法,因此可以嘗試以下方法。

import warnings
# add the following before you call the function that gives warnings.
warnings.filterwarnings("ignore")
# run your function here

我通過檢查BitBucket上項目的問題頁面找到了解決方案。

https://bitbucket.org/haypo/hachoir/issues/54/control-log-level-whith-the-python-api

from hachoir_core import config as HachoirConfig
HachoirConfig.quiet = True

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM