[Tutor] reading and writing with csv then appending some data to a specific line

Kent Johnson kent37 at tds.net
Mon Nov 5 02:54:54 CET 2007

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.


More information about the Tutor mailing list