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
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