如何在if语句之前创建列表?

时间:2019-05-13 10:06:32

标签: sql-server python-3.x

我正在尝试使用for循环从SQL表中创建IP地址列表,并在此表上运行if条件,但是当列表由for循环完成时,结果在最后一个结果中返回正确

def trunk():
    cnxn = pyodbc.connect()
    cursor = cnxn.cursor()
    cursor.execute("")
    lstipin = []
    lstip = []
    for row in cursor.fetchall():
        x1 = str(row[0])
        x2 = row[1]
        x3 = str(row[2])
        x4 = row[3]
        x5 = row[4]
        x = x1.split(".")
        y = x3.split("-")
        lstip.append(x5)
        ipint=int(ipaddress.IPv4Address(x5))
        lstipin.append(int(ipaddress.IPv4Address(x5)))
        prip=ipint -1
        if (x[0] == y[0] and "I0P3" in x1) and ("POC3" and "POC2" in x3):
            if prip in lstipin:
                print(prip, "  ", str(ipaddress.IPv4Address(prip)), "  ", x5)

            print("True", "   ", x1, "   ", x3, "   ", x5)
        else:
            print("False EDESC", x1, x3, x5)

    print(lstipin, "\n",len(lstipin))
    print(lstip, "\n", len(lstip))

    cnxn.commit()

def main():

    trunk()

main()

0 个答案:

没有答案