目标是os在下面的代码中解析依赖项并ls执行命令。
我想知道如何用双星做我在下面发表的评论。
我已经知道我可以通过 traceback
也就是说,我想知道是否可以在给定上下文中的给定行号处恢复程序的执行。
import sys
def new_sys_excepthook(type, value, traceback):
if type == NameError:
pass
# Resolution of the exception finding the module dependency and doing the import
# ** Returning to the line that created the exception with the right
# ** context and continue the execution with the module
# ** dependency resolved
# call original excepthook if we can't solve the issue
sys.__excepthook__(type, value, traceback)
sys.excepthook = new_sys_excepthook
system("ls")
Run Code Online (Sandbox Code Playgroud)