Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/335.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
python中for cycle的问题_Python - Fatal编程技术网

python中for cycle的问题

python中for cycle的问题,python,Python,有时我会遇到这样的函数错误 groupId = cursor.fetchone()[0] File "src\pymssql.pyx", line 507, in pymssql.Cursor.fetchone elif groupFilter: OneMoreList = 'WHERE groupId = ' lst = groupFilter.split(",") for element in groupFilte

有时我会遇到这样的函数错误

    groupId = cursor.fetchone()[0]
  File "src\pymssql.pyx", line 507, in pymssql.Cursor.fetchone
elif groupFilter:
    OneMoreList = 'WHERE groupId = '
    lst = groupFilter.split(",")
    for element in groupFilter.split(","):
        print(element)
        groupId = element
        cursor.execute("SELECT groupId from dbo.CalGroups WHERE groupName='{0}'".format(groupId))
        groupId = cursor.fetchone()[0]
        if len(lst) == 1:
            OneMoreList = OneMoreList + str(groupId)
            print(OneMoreList)
        else:
            OneMoreList = OneMoreList + str(groupId) + ' AND groupId = '     
            print(OneMoreList)
    if len(lst) > 1:         
       OneMoreList = OneMoreList[-15]
       print(":)")
       print(OneMoreList)
但并非总是如此。groupFilter获取这样的值
test1、test2、test3
有时只能获取
test1
test2
我的函数如下所示

    groupId = cursor.fetchone()[0]
  File "src\pymssql.pyx", line 507, in pymssql.Cursor.fetchone
elif groupFilter:
    OneMoreList = 'WHERE groupId = '
    lst = groupFilter.split(",")
    for element in groupFilter.split(","):
        print(element)
        groupId = element
        cursor.execute("SELECT groupId from dbo.CalGroups WHERE groupName='{0}'".format(groupId))
        groupId = cursor.fetchone()[0]
        if len(lst) == 1:
            OneMoreList = OneMoreList + str(groupId)
            print(OneMoreList)
        else:
            OneMoreList = OneMoreList + str(groupId) + ' AND groupId = '     
            print(OneMoreList)
    if len(lst) > 1:         
       OneMoreList = OneMoreList[-15]
       print(":)")
       print(OneMoreList)

知道问题出在哪里吗?

初始错误看起来不完整?例外情况是什么?我知道,但如何更改它并且不丢失获取组名id的点?初始错误看起来不完整?例外情况是什么?我知道,但是如何更改它并且不丢失获取组名id的点?