Home > Mobile >  add and apend data in CSV file
add and apend data in CSV file

Time:10-10

I want to add data into a CSV file. User will enter the value via a PYQT5's line edit input widget. When user click on "add record", the CSV file gets updated.

GUI Layout:

enter image description here

Code Snippet I've tried:

    def addRecord(self):

        list = [self.lineEdit.text(), ',', self.lineEdit_3.text()]
        with open('player_highscore.csv','a') as f_object:

            writer_object = writer(f_object)
            writer_object.writerow(list)

            f_object.close()

With this code, I've tried placing the value 1 for each lineEdit, and have clicked the button twice. This is the output:

LVL,Highscore
10,979161,",",1

1,",",1

How do I resolve this issue? The desired result is:

LVL,Highscore
10,979161
1,1
1,1

CodePudding user response:

It seems the , will be added automatically without writing it.
Try to write this list, instead:

list = [self.lineEdit.text(), self.lineEdit_3.text()]
  • Related