当我尝试运行以下代码时,我得到错误TypeError: object of type 'NoneType' has no len()
(指变量stringConverted
)。我测试了不同的值,对我测试过的值有效。我在想,调试它的最好方法是找出i
的值导致了“NoneType”。所以我尝试在stringConverted = 'NoneType'
处设置一个条件断点,这样当我运行它时,程序应该在这个条件为真时停止。但是当我在设置了条件断点之后尝试运行它时,它会一直运行,产生相同的错误。我做错什么了?我格式化条件断点语句的方式正确吗?在
def main():
totalChars = 0
for i in range(1,500):
stringConverted = stringConvert(i)
totalChars = totalChars + len(stringConverted)
print totalChars
您应该使用
if stringConverted is None
,而不是检查类型是否是NoneType
。在相关问题 更多 >
编程相关推荐