Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/68.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将变量写入mysql时出错_Python_Mysql - Fatal编程技术网

通过python将变量写入mysql时出错

通过python将变量写入mysql时出错,python,mysql,Python,Mysql,我正试图用python(v2.7.6)将一个具有多个条目的变量插入MySQL(Version14.14Distrib5.5.43)表中。代码如下: cur = con.cursor() cur.execute("CREATE TABLE IF NOT EXISTS Stations( \ StationsID INT AUTO_INCREMENT, \ Code VARCHAR(3) ,

我正试图用python(v2.7.6)将一个具有多个条目的变量插入MySQL(Version14.14Distrib5.5.43)表中。代码如下:

cur = con.cursor()
cur.execute("CREATE TABLE IF NOT EXISTS Stations(     \
            StationsID  INT AUTO_INCREMENT,           \
            Code      VARCHAR(3)       ,              \
            PRIMARY KEY pk_Stations (StationsID)      \
            );");

cur.executemany("INSERT INTO Stations (Code) VALUES(?)", sns);
sns
变量具有以下形式:

array(['PAL','TT1','BAL','MHD','BI5','CB4',dtype='S3')

我得到以下错误:

File "/usr/lib/python2.7/dist-packages/MySQLdb/cursors.py", line 199, in executemany
    if not args: return
ValueError: The truth value of an array with more than one element is ambiguous. Use a.any() or a.all()

你能帮我一下吗?

问题解决了。变量应该是一个列表,它是一个
numpy
数组

DUpe:我试过用``符号,但还是有同样的错误。。