Line.Replace - Attribute error

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

  1. davemullen

    davemullen

    Joined:
    Jan 18, 2012
    Messages:
    3
    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. 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. Hugo
    Replies:
    10
    Views:
    1,400
    Matt Humphrey
    Oct 18, 2004
  2. lophiomys@gmx.at
    Replies:
    1
    Views:
    4,421
    Joe Kesselman
    Aug 2, 2006
  3. johnny
    Replies:
    5
    Views:
    757
    johnny
    Dec 10, 2006
  4. kaushikshome
    Replies:
    4
    Views:
    826
    kaushikshome
    Sep 10, 2006
  5. scad
    Replies:
    23
    Views:
    1,221
    Alf P. Steinbach
    May 17, 2009
Loading...

Share This Page