使用条件断点python调试时出现问题

2024-10-02 16:29:18 发布

您现在位置:Python中文网/ 问答频道 /正文

当我尝试运行以下代码时,我得到错误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

Tags: of方法no代码lenobjecttype错误
2条回答
def main():
    totalChars = 0
    for i in range(1,500):
        stringConverted = stringConvert(i)
        if stringConverted is None:
            print i
            break
        totalChars = totalChars + len(stringConverted)
    else:
        print "No error!"
    print totalChars

您应该使用if stringConverted is None,而不是检查类型是否是NoneType。在

相关问题 更多 >