Help don't know what problem is Newbie

Discussion in 'Python' started by len, Aug 23, 2006.

  1. len

    len Guest

    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
     
    len, Aug 23, 2006
    #1
    1. Advertising

  2. len

    Peter Otten Guest

    len wrote:


    > Have the following code:


    Short variable names increase the likelihood of name clashes:

    > c = db.cursor()


    > c = ''


    > 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
     
    Peter Otten, Aug 23, 2006
    #2
    1. Advertising

  3. len

    len Guest

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

    Thanks
    Len Sumnler

    Peter Otten wrote:
    > len wrote:
    >
    >
    > > Have the following code:

    >
    > Short variable names increase the likelihood of name clashes:
    >
    > > c = db.cursor()

    >
    > > c = ''

    >
    > > 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
     
    len, Aug 24, 2006
    #3
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. DP
    Replies:
    0
    Views:
    1,156
  2. Replies:
    5
    Views:
    533
  3. pplnet
    Replies:
    2
    Views:
    2,675
    marina_yassa
    Mar 29, 2013
  4. Kaldrenon
    Replies:
    3
    Views:
    157
    Sebastian Hungerecker
    Jul 17, 2007
  5. Andries

    I know, I know, I don't know

    Andries, Apr 23, 2004, in forum: Perl Misc
    Replies:
    3
    Views:
    253
    Gregory Toomey
    Apr 23, 2004
Loading...

Share This Page