ASPN ActiveState Programmer Network
ActiveState
/ Home / Perl / PHP / Python / Tcl / XSLT /
/ Safari / My ASPN /
Cookbooks | Documentation | Mailing Lists | Modules | News Feeds | Products | User Groups


Recent Messages
List Archives
About the List
List Leaders
Subscription Options

View Subscriptions
Help

View by Topic
ActiveState
.NET Framework
Open Source
Perl
PHP
Python
Tcl
Web Services
XML & XSLT

View by Category
Database
General
SOAP
System Administration
Tools
User Interfaces
Web Programming
XML Programming


MyASPN >> Mail Archive >> python-tutor
python-tutor
[Tutor] School Boy Error - Update
by John CORRY other posts by this author
Apr 16 2006 4:33AM messages near this date
Re: [Tutor] Stack Diagrams | Re: [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.
 
Thread:
John CORRY
Liam Clarke

Privacy Policy | Email Opt-out | Feedback | Syndication
© 2004 ActiveState, a division of Sophos All rights reserved