Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/361.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 我需要创建一个包含变量名称的表_Python_Sql - Fatal编程技术网

Python 我需要创建一个包含变量名称的表

Python 我需要创建一个包含变量名称的表,python,sql,Python,Sql,为了 如何:“插入到%(变量)(id)值(%s)”中 问题是代码严格地将变量名me作为文本,而不是指定它所在的变量名 其思想是在表之间找到变量“12345”的名称,如果没有,则使用变量名称创建表: idunidad = 2501 sql = ("""insert into %(variable)s ( id ) VALUES (%s)""") if cursor.execute(sql, (idunidad,) % {table_name: table_name}): db.commit

为了

如何:“插入到%(变量)(id)值(%s)”中

问题是代码严格地将变量名me作为文本,而不是指定它所在的变量名

其思想是在表之间找到变量“12345”的名称,如果没有,则使用变量名称创建表:

idunidad = 2501
sql = ("""insert into %(variable)s ( id ) VALUES (%s)""")
if cursor.execute(sql, (idunidad,) % {table_name: table_name}):
    db.commit()
    cursor.close()
    db.close()
variable = '12345'
idunidad = 2501
sql = ("""insert into %(variable)s ( id ) VALUES (%s)""")
if cursor.execute(sql, (idunidad,) % {table_name: table_name}):
    db.commit()
    cursor.close()
    db.close()
else:
    cursor.execute('''create table variable stocks (id)''')
    cursor.execute(sql,(id,))
    db.commit()
    cursor.close()
    db.close()
variable = '12345'
idunidad = 2501
sql = ("""insert into u_%(variable)s ( id ) VALUES (%(idunidad)s)""" % dict(table_name = table_name))
try:
    cursor.execute(sql):
    db.commit()
    cursor.close()
    db.close()
except:
    cursor.execute('''create table u_%(variable)s stocks (id)''' % dict(table_name = table_name))
    cursor.execute(sql)
    db.commit()
    cursor.close()
    db.close()