Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/325.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
MySQL/Python在for循环中的字典迭代中出现“NoneType”错误_Python_Mysql_Sql_For Loop_Nonetype - Fatal编程技术网

MySQL/Python在for循环中的字典迭代中出现“NoneType”错误

MySQL/Python在for循环中的字典迭代中出现“NoneType”错误,python,mysql,sql,for-loop,nonetype,Python,Mysql,Sql,For Loop,Nonetype,当我使用原始输入创建填充dict时,它的形式为{'Key1':['Example','String'],'Key2':['Random','String']},在查询循环遍历'c'中的第一个索引后,我发现错误'NoneType'对象不可iterable'。有人能解释一下吗 #Give the user the option to pick which elements to sort by patient_array = [1295, 1736, 1744, 2132] input_parame

当我使用原始输入创建填充dict时,它的形式为{'Key1':['Example','String'],'Key2':['Random','String']},在查询循环遍历'c'中的第一个索引后,我发现错误'NoneType'对象不可iterable'。有人能解释一下吗

#Give the user the option to pick which elements to sort by
patient_array = [1295, 1736, 1744, 2132]
input_parameters = raw_input('Select paramaters to sort by: ').split(', ')
input_list = [str(a) for a in input_parameters]
print input_list
parameter_dict = {'Melanoma Bank Number' : 'MB', 'Chromosome' : 'Chromosome', 'Start' : 'Start', 'End' : 'End', 'Gene' : 'Gene Type1'}
query_list = dict()
#Query parameters within the chosen elements
for parameter in input_list:
    parameter_input = raw_input('Select ' + parameter + ': ').split(', ')
    parameter_input = [str(a) for a in parameter_input]
    print parameter_input
    query_list[parameter] = parameter_input
print query_list    


#First query loop
def query_loop(n):
    c = query_list[input_list[n]]
    for index in patient_array:
        for x in c:
            cursor.execute("SELECT * FROM `%s` WHERE `%s` = '%s'" % (index, parameter_dict[input_list[n]], x))
            row = cursor.fetchone()
            while(row):
                #print row
                row = cursor.fetchone()
                cursor2.execute("INSERT INTO query_table VALUES (\"%s\", \"%s\", \"%s\", \"%s\", \"%s\", \"%s\", \"%s\", \"%s\", \'%s\')" % tuple(row))
                conn.commit()

#Subquery for parameter(n) where n >0
def subquery(n):
    c = query_list[input_list[n]]
    for x in c:
        cursor3.execute("DELETE FROM query_table WHERE `%s` <> '%s'" % (parameter_dict[input_list[n]], x))
        conn.commit()
下面是我用来迭代两个函数的while循环:

n = 0 
while n <= len(input_list):
    if n == 0:
        query_loop(n)
        n = n + 1
    elif n < len(input_list):
        subquery(n)
        n = n + 1
    else:
        cursor.execute("SELECT * FROM query_table")
        print cursor.fetchall()
    n = n + 1    

我不明白你的问题。您的错误在哪里?程序在c中运行一个x,该参数中的行被插入MySQL表query_表中,但是在这之后,我得到了'NoneType'错误