当ipython笔记本调试中出现错误时,如何在更正值后继续运行?

当ipython笔记本调试中出现错误时,如何在更正值后继续运行?,python,debugging,jupyter-notebook,pdb,ipdb,Python,Debugging,Jupyter Notebook,Pdb,Ipdb,比如说, def power(x, n): res = 1 for i in range(n): res *= x return res power('10',5) 然后,它将引发如下错误 TypeError: can't multiply sequence by non-int of type 'str' 现在,我尝试在新的笔记本单元中使用%debug进行调试 ipdb> x = int(10) ipdb> c 但是,在%debug中,

比如说,

def power(x, n):
    res = 1
    for i in range(n):
        res *= x
    return res
power('10',5)
然后,它将引发如下错误

TypeError: can't multiply sequence by non-int of type 'str'
现在,我尝试在新的笔记本单元中使用
%debug
进行调试

ipdb> x = int(10)
ipdb> c
但是,在
%debug
中,如果我在
ipdb
中使用
c
这意味着
continue
,它将无法在值更改后继续运行
x

因此,我想知道是否有任何方法可以在调试时更正变量的值并继续运行


更新:

这只是一个例子


事实上,在某些情况下,我希望长时间运行代码,中途会出现错误。我想更正错误并尝试继续运行代码。您知道,简单地重新运行可能需要很长时间。

检查以下解决方案:

x
值不应为
str
类型

使用
power(10,5)
代替
power('10',5)

转换代码中
x
的值:

def power(x, n):
    res = 1
    for i in range(n):
        res *= int(x)
    return res
print(power('10',5))

你考虑过使用try/except吗?我更新了我的需求。实际上,我想知道如何在调试模式下进行有效的调试。