1

I'm stuck here with a small Problem. I have a python tcp Server running on my pc reciving data from a Client. I Need to automaticly write a csv file. now the only Problem is data is being overwritten in the first row, is there a way to give an index to the data I'm reciving? help would be great. Thanks!

#while connected
while 1:
    data = con.recv(Buffer_size)
    writer  = csv.writer(open(filename+".csv", 'w')
    writer.writerow('\n'data)
Rakesh
  • 81,458
  • 17
  • 76
  • 113

1 Answers1

1

You send the argument 'w' to open(). 'w' means

w: open for writing, truncating the file first

(https://docs.python.org/3/library/functions.html#open)

Change this to 'a'

a: open for writing, appending to the end of the file if it exists

and you will append to the end of the file.

I.e.

#while connected
while 1:
    data = con.recv(Buffer_size)
    writer  = csv.writer(open(filename+".csv", 'a')
    writer.writerow('\n'data)
Cleared
  • 2,490
  • 18
  • 35