[Tutor] School Boy error
Hi, I couldnt sleep last night with all the code running though my head. Counting sheep didnt work as I kept wanting to turn them into a loop! listy[-1] Outputs the following:- ['432', 'TM BLIND', 'RO', 'PF1', 'Plain Finish Range One', '304.8', '', '45.7', '80', '90', '0', '39', '61', '15.03', '33', '0', '46', '81.3', '19.38', '42', '0', '60', '101.6', '22.39', '49', '0', '69', '121.9', '26.39', '58', '0', '81', '142.2', '30.4', '67', '0', '93', '162.6', '34.41', '75', '0', '105', '182.9', '38.08', '83', '0', '117', '198.1', '41.42', '90', '0', '127', '223.5', '48.77', '106', '0', '149', '243.8', '53.12', '117', '0', '163', '274.3', '60.8', '133', '0', '186', '304.8', '66.14', '145', '0', '202', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0\n'] The full error is Traceback (most recent call last): File C:\Python24\Lib\site-packages\databasemanager.py, line 30, in ? c.execute(stat, listy[-1]) TypeError: parameters must be a list of tuples Thanks, John. ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] School Boy error
instead of c.execute(stat, listy[-1]) try sql_list = listy[-1] c.execute(stat, sql_list) Also what does print stat give you? maybe one of those two would tell us .. Bri! John CORRY wrote: Hi, I couldn’t sleep last night with all the code running though my head. Counting sheep didn’t work as I kept wanting to turn them into a loop! listy[-1] Outputs the following:- ['432', 'TM BLIND', 'RO', 'PF1', 'Plain Finish Range One', '304.8', '', '45.7', '80', '90', '0', '39', '61', '15.03', '33', '0', '46', '81.3', '19.38', '42', '0', '60', '101.6', '22.39', '49', '0', '69', '121.9', '26.39', '58', '0', '81', '142.2', '30.4', '67', '0', '93', '162.6', '34.41', '75', '0', '105', '182.9', '38.08', '83', '0', '117', '198.1', '41.42', '90', '0', '127', '223.5', '48.77', '106', '0', '149', '243.8', '53.12', '117', '0', '163', '274.3', '60.8', '133', '0', '186', '304.8', '66.14', '145', '0', '202', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0\n'] The full error is Traceback (most recent call last): File C:\Python24\Lib\site-packages\databasemanager.py, line 30, in ? c.execute(stat, listy[-1]) TypeError: parameters must be a list of tuples Thanks, John. !DSPAM:444211df223121389011208! ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor !DSPAM:444211df223121389011208! ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
[Tutor] School Boy Error
Bri, Print stat gives Insert into cost_grid values (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?, ?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?, ?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?, ?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,) Traceback (most recent call last): File C:\Python24\Lib\site-packages\databasemanager.py, line 31, in ? c.execute(stat, sql_list) TypeError: parameters must be a list of tuples Unfortunately sql_list gives the same error. Thanks, John. ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
[Tutor] School Boy Error - Update
Hi, I have taken on board the advice in relation to the cvs module and setting the list to a tuple. I am now using the following code and getting a different error. I think it is a small step forward? import string, re path = c:/test/import.csv listy = [] import csv reader = csv.reader(open(path,rb)) for row in reader: listy.append(tuple(row)) sql_list = listy[0] stat = Insert into cost_grid values (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?, ?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?, ?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?, ?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,) t = 5000 d = PF2 b = 91.4 a = 95.00 print stat print sql_list import mx.ODBC import mx.ODBC.Windows db = mx.ODBC.Windows.DriverConnect('DSN=vfp') c = db.cursor() c.execute(stat, sql_list) db.commit() c.close() I now get the following ouput + error: Insert into cost_grid values (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?, ?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?, ?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?, ?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,) ('961', 'TM BLIND', 'RO', 'PF1', 'Plain Finish Range One', '91.4', '', '45.7', '10', '20', '0', '24', '61', '8.69', '20', '0', '27', '81.3', '11.03', '25', '0', '34', '101.6', '12.36', '28', '0', '38', '121.9', '14.36', '32', '0', '44', '142.2', '16.7', '37', '0', '51', '162.6', '18.71', '41', '0', '58', '182.9', '20.72', '45', '0', '64', '198.1', '22.71', '49', '0', '70', '223.5', '27.39', '60', '0', '84', '243.8', '30.07', '66', '0', '92', '274.3', '34.41', '76', '0', '105', '304.8', '37.42', '82', '0', '115', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0') Traceback (most recent call last): File C:\Python24\Lib\site-packages\databasemanager.py, line 35, in ? c.execute(stat, sql_list) ProgrammingError: ('37000', 200, '[Microsoft][ODBC Visual FoxPro Driver]Syntax error.', 4347) I assume this error is telling me that the database does not like the syntax of the data I am importing. The data that I am importing is actually data that I exported, so I know that it is in the right order and the right amount. The only thing that I can think of is that, the database requires floats for the numbers instead of strings. I assume that the numbers in listy[0] are now strings. Am I now going to have to throw listy[0] through a function to make the numbers into floats or is there another way to do this? Am I on the right track? Thanks, John. ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] School Boy Error
I wonder if it could not be the extra comma (,) at the end of your sql ? thus: ..?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,)--- see trailing comma, and no matching ? could be a value count != column count mis-match make sure you have the correct number of values to each column :) On the other hand, it is also possible, if ODBC is strict about taking strings and ints, that you need to run a function to convert list items to integer values where an integer is required.. John CORRY wrote: Bri, Print stat gives Insert into cost_grid values (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?, ?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?, ?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?, ?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,) Traceback (most recent call last): File C:\Python24\Lib\site-packages\databasemanager.py, line 31, in ? c.execute(stat, sql_list) TypeError: parameters must be a list of tuples Unfortunately sql_list gives the same error. Thanks, John. !DSPAM:44421f56263591105852714! ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor !DSPAM:44421f56263591105852714! ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] School Boy Error
Hi John, Listy will be a list of lists, and the DBAPI specifies tuples. So either change this - listy.append(line) to listy.append(tuple(line)) or stick a list comprehension at the end if you need to mung anything in listy before passing it in: listy = [ tuple(item) for item in listy] Regards, Liam Clarke On 4/16/06, John CORRY [EMAIL PROTECTED] wrote: Thanks Brian for the help on the last one. I couldn't see the wood for the trees. I have a tougher one for you. I am reading in a CSV file. Each line represents a line that I want to upload into my database. I am trying to upload the first line in the file to get myself started. The code is below:- import string, re path = c:/test/import.csv listy = [] input = file(path, r) for line in input.readlines(): line = line.split(,) listy.append(line) print listy[-1] stat = Insert into cost_grid values (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?, ?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?, ?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?, ?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,) t = 5000 d = PF2 b = 91.4 a = 95.00 import mx.ODBC import mx.ODBC.Windows db = mx.ODBC.Windows.DriverConnect('DSN=vfp') c = db.cursor() c.execute(stat, listy[-1]) db.commit() c.close() I get the following error: TypeError: parameters must be a list of tuples Any suggestions would be greatly appreciated. Thanks, John. ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] School Boy Error
Wait, I have put you wrong there. Can you please copy and paste here the output of print liney[-1] Thanks, Liam On 4/16/06, Liam Clarke [EMAIL PROTECTED] wrote: Hi John, Listy will be a list of lists, and the DBAPI specifies tuples. So either change this - listy.append(line) to listy.append(tuple(line)) or stick a list comprehension at the end if you need to mung anything in listy before passing it in: listy = [ tuple(item) for item in listy] Regards, Liam Clarke On 4/16/06, John CORRY [EMAIL PROTECTED] wrote: Thanks Brian for the help on the last one. I couldn't see the wood for the trees. I have a tougher one for you. I am reading in a CSV file. Each line represents a line that I want to upload into my database. I am trying to upload the first line in the file to get myself started. The code is below:- import string, re path = c:/test/import.csv listy = [] input = file(path, r) for line in input.readlines(): line = line.split(,) listy.append(line) print listy[-1] stat = Insert into cost_grid values (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?, ?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?, ?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?, ?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,) t = 5000 d = PF2 b = 91.4 a = 95.00 import mx.ODBC import mx.ODBC.Windows db = mx.ODBC.Windows.DriverConnect('DSN=vfp') c = db.cursor() c.execute(stat, listy[-1]) db.commit() c.close() I get the following error: TypeError: parameters must be a list of tuples Any suggestions would be greatly appreciated. Thanks, John. ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] School Boy Error
* John CORRY [EMAIL PROTECTED] [2006-04-15 23:48]: Thanks Brian for the help on the last one. I couldn't see the wood for the trees. I have a tougher one for you. I am reading in a CSV file. Each line represents a line that I want to upload into my database. I am trying to upload the first line in the file to get myself started. The code is below:- You may want to check out the csv module to aid in any odd data input, too. http://docs.python.org/lib/module-csv.html -- David Rock [EMAIL PROTECTED] ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor