[英]When is the attribute `isatty()` not present in sys.stderr?
我的猜測是,這只會在sys.stderr
被模擬或猴子修補時發生。
例如,您引用的第一個GitHub問題具有以下錯誤消息:
AttributeError: 'UnicodeStdout' object has no attribute 'isatty'
這個類UnicodeStdout
不在標准庫中,我的研究向我指出了hachoir lib的舊版本(例如, commit )。
第二個鏈接還有另一個可疑的錯誤消息,其中單獨的類名稱表明sys.stdout
被弄亂了:
AttributeError: '_StdoutProxy' object has no attribute 'isatty'
此類似乎像一個“代理”,並未實現原始sys.stdout
所有方法。 這不僅會影響isatty()
,而且可能還會影響其他屬性,例如fileno
(例如,請參見此其他問題 。)
您可以自己對屬性進行猴子修補:
sys.stderr = SomeProxyClass()
或添加支票,例如:
if hasattr(sys.stderr, 'isatty') and sys.stderr.isatty()
但在大多數情況下,這是沒有必要的。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.