用条件断点python调试问题

时间:2011-08-11 20:19:31

标签: python debugging conditional-breakpoint

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

2 个答案:

答案 0 :(得分:0)

您应该使用if stringConverted is None而不是检查类型以查看它是否为NoneType

答案 1 :(得分:0)

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