Forwarding to the list...

-------- Original Message --------
Subject:        Re: [Tutor] reading and writing with csv then appending some
data to a specific line
Date:   Mon, 5 Nov 2007 14:54:49 +0100
From:   pierre cutellic <[EMAIL PROTECTED]>
To:     Kent Johnson <[EMAIL PROTECTED]>
References:
<[EMAIL PROTECTED]>
<[EMAIL PROTECTED]>



many thanks,
but i don't really want to erase the content of the file i'm writing to.
This script was a first step for me to understand how to write to a file
at a given line of the file without erasing its content. I didn't really
understood the code you linked me:
http://mail.python.org/pipermail/python-list/2000-August/048839.html .
when i'm using seek(), data is appended to the end of the file.:(

On Nov 5, 2007 2:54 AM, Kent Johnson <[EMAIL PROTECTED]
<mailto:[EMAIL PROTECTED]>> wrote:

     pierre cutellic wrote:
      > Hi,
      > I wrote this script to select some data from a csv file.
      > Actually it writes it into a file but i would like to append it
     into an
      > existing one to a specific line without removing existing code.
      >  does the open(' filename.csv','a+') can do that?
      >
      >         ag = elem[0]
      >         ag.split(";")

     Here I think you want
       ag = ag.split(';')
     split() does not split the string in place, it returns a new list with
     the split elements.

     Also you are opening the file for writing (which will erase the
     contents) before you read it.

     Other than that your code looks OK. You might want to try writing it
     without functions, I think they may be confusing you a bit and they are
     not really needed here.

     Kent




-- 
Pierre Cutellic____________
OO   33   6   15   67   17   85
[EMAIL PROTECTED] <http://gmail.com>
_______________________________________________
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor

Reply via email to