Python列表无法识别数据库选项卡中的值

2024-09-30 08:35:17 发布

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

我想知道为什么代码不能识别10/11的字段值在list['10','11']中,以及为什么它会绕过初始if语句

任何可能的解决方案都会非常感激,代码下面还有运行代码后生成的print语句

    TableRow = DBSelect.fetchall()
    for Field in TableRow:
        print(Field, "This is the currently looped ID")
        print(EList, "This is the EList")
        if Field in EList : # compares each  ID against the EList
            print(EList, "This is pre- modified EList")
            EList.pop([Field]) # removes the ID from EList
            print(EList, "This is post- modified EList")
            UnavailableE = UnavailableE + 1 #Add to the number of unavailable E
            print(UnavailableE, "This is the Unavailable e in the loop")
        elif UnavailableE == ECount: # if the UnavailableE is Equal to  ECount, then no ID available - runs this output
            print("No e available")
        else:  
            print("Not in list")

为进一步参考,以下是由此产生的打印语句:

10这是当前循环的ID

['10','11']这是EList

不在列表中

11这是当前循环的ID

['10','11']这是EList

不在列表中


Tags: the代码inidfieldifis语句
2条回答
for Field in TableRow:
    Field = Field.strip()
    print(Field, "This is the currently looped ID")
    print(EList, "This is the EList")

将strip添加到strip字段的开头和结尾空格

如果Field不是字符串(数字?)或字符串"10",那么它就不在列表中,因为列表包含字符串"10 ""11 "(注意后面的空格)

相关问题 更多 >

    热门问题