我正在學習python,而且我是新的bie。 我想使用的功能與MySQL和Python和我是個得到錯誤在Python中執行許多錯誤
這是我的腳本
import MySQLdb
def insert_values(cursor, values):
#cursor = self.connection.cursor()
cursor.executemany("""
insert into pythontest (name1,name2,name3)
values (%s, %s, %s)""", values)
cursor.close()
db = MySQLdb.connect("localhost","root","root","python")
cursor = db.cursor()
var1 = ['name1','name2','name3']
insert_values(cursor,var1)
db.close()
可能有很多錯誤,因爲我正在學習
1)i don't know how can i pass db object in function or passing cusrsor is ok. because i have to call that function many times in for loop
2)is the syntax of values array ok to go in database
錯誤
File "mysql.py", line 10, in insert_values
values (%s, %s, %s)""", values)
File "build/bdist.linux-i686/egg/MySQLdb/cursors.py", line 216, in executemany
File "build/bdist.linux-i686/egg/MySQLdb/connections.py", line 36, in defaulterrorhandler
_mysql_exceptions.ProgrammingError: not enough arguments for format string
請指出您看到的錯誤。 – 2011-05-21 09:12:50
我已添加錯誤 – Mahakaal 2011-05-21 09:18:03