Help don't know what problem is Newbie

L

len

Have the following code:

import os
import csv
import re
import mx.ODBC
import mx.ODBC.Windows

currdir = os.getcwd()
db = mx.ODBC.Windows.DriverConnect('dsn=UICPS Test')
c = db.cursor()
sid = 315

matchstr = re.compile(r'\(*\)*-*,*')
reader = csv.reader(open(currdir + r'\\IBI Brokers List 8-21-06.csv'))

for rec in reader:
if rec[0] != '' or rec[1] != '':
if rec[0] == 'Name:':
orec = ''
orec = orec + rec[12] + ',' + rec[2]
elif rec[1] == 'Address1':
orec = orec + ',' + rec[4]
elif rec[1] == 'Address2':
orec = orec + ',' + rec[4]
elif rec[1] == 'City, State, ZIP':
csz = matchstr.sub('', rec[4]).split()
if len(csz) == 0:
c = ''
s = ''
z = ''
elif len(csz) == 3:
c = csz[0]
s = csz[1]
z = csz[2]
elif len(csz) == 4:
c = csz[0] + ' ' + csz[1]
s = csz[2]
z = csz[3]
orec = orec + ',' + c + ',' + s + ',' + z + ',' +
matchstr.sub('', rec[13])
elif rec[1] == 'Tax ID':
orec = orec + ',' + rec[4].replace('-', '') + ',' +
matchstr.sub('', rec[12])
sid += 1
orec = str(sid) + ',' + orec
print orec
c.execute("insert into Producer \
(Producer_Sid, Producerno, Company, Street, Suitepo, City,
State, Zip, \
Phone, Taxid, Fax) \
values (" + orec + ")")

Below is a listing of the orec which I printed along with the python
error:

[DEBUG ON]316,001,#001 Insurance Brokers of Indiana,400 Camby Court,P O Box
190,Greenwood,IN,46142,3178882593 ,351539405,3178857011

Traceback (most recent call last):
File "C:\UICPS\IBIagent.py", line 44, in -toplevel-
c.execute("insert into Producer \
AttributeError: 'str' object has no attribute 'execute'

Thanks
Len Sumnler
 
L

len

Sorry for the stupid question. I was fixated on the SQL.

Thanks
Len Sumnler

Peter said:
len wrote:

Have the following code:

Short variable names increase the likelihood of name clashes:
c = db.cursor()
c = csz[0]
c = csz[0] + ' ' + csz[1]
c.execute("insert into Producer \
(Producer_Sid, Producerno, Company, Street, Suitepo, City,
State, Zip, \
Phone, Taxid, Fax) \
values (" + orec + ")")

Peter
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,055
Latest member
SlimSparkKetoACVReview

Latest Threads

Top