'Write new data in to csv file in Python from an Arduino

I'm receiving data from an Arduino each second but I can't save it, it writes the continous data in the same cell on the csv file and just is changed it each time that the new value is getted. I'm triying with the newline='' and the write row but is not working.

valueenc = (value)
                print("Valueencoded", valueenc)
                #print("Message received: "  + valueenc)
                f = open(f'{root_path}/Desktop/microphone_dump.csv','w+', newline ='')
                #f.write(valueenc)
                with f:
                    write = csv.writer(f) 
                    write.writerows(valueenc)


Solution 1:[1]

this is the way:

file = open(f'{root_path}/Desktop/test.csv', "a")
                print("Created file")
                file = open(f'{root_path}/Desktop/test.csv', "a") #append the data to the file
                file.write(valueenc + "\n") #write data with a newline
                #close out the file
                file.close()

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Eduardomaker