CSV Issue

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Rohan

    #1

    CSV Issue

    I'm having a trouble consider this

    import csv
    f = open("/home/t/tp/va/some7.csv", "rb")
    reader =csv.reader(f)
    rows =[]
    for row in reader:
    rows.append(row )



    rows[1].append('1')

    print rows
    f = open("/home/t/tp/va/e7.csv", "ab")
    writer =csv.writer(f)

    writer.writerow s(rows)
    f.close()

    In the file some7.csv there is already some data like this
    1
    2
    3
    4
    Now i'm trying to add a '1' in row2 so that data can be like this
    1
    2,1
    3
    4
    Instead i'm getting like this
    1
    2
    3
    4
    1
    2,1
    3
    4

    can some one explain this and how to get it in the way i want it/

  • John Machin

    #2
    Re: CSV Issue

    On Jul 27, 7:19 am, Rohan <vodela....@gma il.comwrote:
    f = open("/home/t/tp/va/e7.csv", "ab")
    a means Append -- you are appending the data that you expect to the
    EXISTING contents of the file.


    Comment

    • Rohan

      #3
      Re: CSV Issue

      On Jul 26, 2:32 pm, John Machin <sjmac...@lexic on.netwrote:
      On Jul 27, 7:19 am, Rohan <vodela....@gma il.comwrote:
      >
      f = open("/home/t/tp/va/e7.csv", "ab")
      >
      a means Append -- you are appending the data that you expect to the
      EXISTING contents of the file.
      Hello John,
      Yea silly mistake, write mode will do.
      thanks

      Comment

      Working...