Line.Replace - Attribute error

Discussion in 'Python' started by davemullen, Jan 20, 2012.

  1. davemullen

    davemullen

    Joined:
    Jan 18, 2012
    Messages:
    3
    Likes Received:
    0
    Hi,

    I am trying to replace spaces with underscores in a header record.
    At this time I am only printing so I can see the results. When I get it to work I will write.
    I am getting an attribute error on the line.replace.
    Any ideas?

    import csv
    infile = open("fileexchange_response_12458229.csv", "r")
    reader = csv.reader(infile)
    record_cntr = 0
    for line in reader:
    if record_cntr == 0: #header line
    print line # orig header line
    line = line.replace(" ", "_") # replace spaces w/underscores
    print line # header line fixed
    record_cntr += 1
    elif record_cntr <> 0 : #detail
    print line
    record_cntr += 1
     
    davemullen, Jan 20, 2012
    #1
    1. Advertisements

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 (here). After that, you can post your question and our members will help you out.
Similar Threads
  1. Hugo
    Replies:
    10
    Views:
    1,707
    Matt Humphrey
    Oct 18, 2004
  2. Brian Blais
    Replies:
    1
    Views:
    620
    Bruno Desthuilliers
    Jun 27, 2006
  3. lophiomys@gmx.at
    Replies:
    1
    Views:
    5,125
    Joe Kesselman
    Aug 2, 2006
  4. johnny
    Replies:
    5
    Views:
    1,027
    johnny
    Dec 10, 2006
  5. ben
    Replies:
    4
    Views:
    935
    Martin Ambuhl
    Jun 26, 2004
  6. kaushikshome
    Replies:
    4
    Views:
    1,128
    kaushikshome
    Sep 10, 2006
  7. scad
    Replies:
    23
    Views:
    1,599
    Alf P. Steinbach
    May 17, 2009
  8. Marek Stepanek
    Replies:
    12
    Views:
    762
    Peter J. Holzer
    Sep 2, 2006
Loading...