簡體   English   中英

如何抑制特定類型的警告消息?

[英]How do I suppress a specific type of warning message?

我知道使用warnings.filterwarnings('ignore')會抑制警告消息,但是我想抑制特定類型的警告。

更具體地說,此警告消息是由我正在使用的第三方庫提供的,日志警告消息如下所示:

04/23/2021 21:09:39 - WARNING - pytorch_transformers.tokenization_utils -  Token indices sequence length is \
longer than the specified maximum sequence length for this model (589 > 512). Running this sequence through the \
model will result in indexing errors

我不確定我應該如何通過使用正則表達式或其他東西來抑制警告消息。 我不想將 go 轉換為實際腳本並進行更改,我想知道是否有辦法找出抑制此警告消息的具體方法。 謝謝。

您可以在 filterwarnings 方法中將正則表達式分配給消息關鍵字。

warnings.filterwarnings('ignore', message='model will result in indexing errors*')

參考: https://docs.python.org/3/library/warnings.html

暫無
暫無

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

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