wmic /output:wmicbuild.csv product get InstallDate,InstallLocation,Name,Vendor,Version /format:csv
import csv import MySQLdb filepath = r"wmicbuild.csv" mydb = MySQLdb.connect(host='localhost', user='login', passwd='password', db='test') cursor = mydb.cursor() with open(filepath, encoding='utf-16') as csvfile: csv_data = csv.reader(csvfile) strSQL = r"INSERT INTO csv(node,installdate,installlocation,name,vendor,version) VALUES(%s, %s, %s, %s, %s, %s)" for row in csv_data: #print(row) cursor.execute(strSQL, row) #close the connection to the database. mydb.commit() cursor.close() print ("Done")
В результате возникает ошибка
query = query % args TypeError: not enough arguments for format string
В файле “wmicbuild.csv” содержится следующая информация
Node,InstallDate,InstallLocation,Name,Vendor,Version User,20151221,,Python 3.2.7 Add to Path (32-bit),Python Software Foundation,3.2.7.0 User,20140624,C:\Program Files\OpenXML-ODF Translator\,ODF Add-in for Microsoft Office,OpenXML/ODF Translator Team,4.0.5309.0 User,20151221,,Python 3.2.7 Documentation (32-bit),Python Software Foundation,3.2.7.0
Что я делаю не так?