例如,
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
中,如果我使用c
(这意味着在ipdb
中继续
),它可以' t 继续以更改后的值 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))
关于python - ipython Notebook调试出现bug时如何更正数值后继续运行?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59560190/