1

私はしばらくこの python コードと格闘しており、実行しようとするとさまざまなエラーが発生します。

import csv
import MySQLdb
# open the connection to the MySQL server.
# using MySQLdb
mydb = MySQLdb.connect(host='myhostinfo',
user='me',
passwd='mypw',
db='thedatabase')
cursor = mydb.cursor()
# read the presidents.csv file using the python
# csv module http://docs.python.org/library/csv.html
csv_data = csv.reader(file('CHN-mod.csv'))
# execute the for clicle and insert the csv into the
# database.
for row in csv_data:

    cursor.execute('INSERT INTO INDICATORS(INDICATORNAME, \
            , INDICATORCODE)' \
            'VALUES(%s, %s)',  row)
#close the connection to the database.
cursor.close()
print "Import to MySQL is over"

コードはオンラインの Python バリデーターで検証されますが、エラーが発生します。

Traceback (most recent call last):
  File "importdata.py", line 23, in <module>
    'VALUES(%s, %s)' , row)
  File "/usr/local/lib/python2.7/dist-packages/MySQLdb/cursors.py", line 201, in execute
    self.errorhandler(self, exc, value)
  File "/usr/local/lib/python2.7/dist-packages/MySQLdb/connections.py", line 36, in defaultterrorhandler
    raise errorclass, errorvalue
_mysql_exceptions.ProgrammingError: (1064, "You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ' INDICATORCODE)VALUES('Indicator Name', 'Indicator Code'>' at line 1")
4

1 に答える 1