在這種情況下,實現新命令很有用,例如可能的ignored [Excepions]
而不是將它們定義爲函數?Python函數與Cpython命令執行
'忽略' contextmanager:
import contextlib
@contextlib.contextmanager
def ignored(*exceptions):
try:
yield
except exceptions:
pass
用法:
with ignored(IndexError, KeyError):
## inside code here
可能的替代:
ignored IndexError, KeyError:
## inside code here
你打算如何實施替代方案?你打算更新Python解析器嗎? – tdelaney
@tdelaney是的,我想知道你對於優缺點的看法... – JumpAlways
擺弄python解析器很困難,然後你最終會得到一個非標準的解釋器,可能會有少許攝取。除了用於練習的玩具實施外,我認爲沒有好處。如果你喜歡這個挑戰,那就去做吧,但我不會把它叫做對別人有用的! – tdelaney