About Writing to a csv File

Asked 2 years ago, Updated 2 years ago, 106 views

If you execute it with the following code, the input data will be saved in the csv file, but the data will be deviated from the label and there will be no "Register" data.
Is the loading bad?Is the label on the file bad?
Could you tell me the solution?

import tkinter ask
import csv




class file1_1:
    default file1_2(self):
        mn = tk.Tk()
        mn.geometry ('1500x1000')
        mn.title ("Inventory Management System")

        def new1_1():
            mn.destroy()
            file1().file2()

        lab1_1=tk.Label(text="Main Monitor", font=(",45))
        lab1_1.place(x=40,y=20)
        lab1_2=tk.Label(text="Incoming and outgoing processing menu", font=(",30))
        lab1_2.place(x=40,y=110)

        bot1_1=tk.Button(mn, text="Incoming process", font=(",50), width=20, command=new1_1)
        bot1_1.place(x=40,y=170)
        bot1_2=tk.Button(mn, text="Delivery Processing", font=(",50), width=20)
        bot1_2.place(x=750,y=170)

        mn.mainloop()


class file1:
    default file2(self):
        lt = tk.Tk()
        lt.geometry ('600x600')
        lt.title ("Registration Monitor")

        defbot1_1():
            detail = [ ]
            detail.append(txt1.get())
            detail.append(txt2.get())
            detail.append(txt3.get())
            detail.append(txt4.get())


            with open('deta.csv', 'a') ascsvFile:
                writer=csv.writer(csvFile)
                writer.writerow (detaset)

            txt1.delete(0,tk.END)
            txt2.delete(0,tk.END)
            txt3.delete(0,tk.END)
            txt4.delete(0,tk.END)

            return

        default_1():
            lt.destroy()
            file1_1().file1_2()


        lab1=tk.Label(text="Product registration", font=(",40))
        lab1.place(x=20,y=30)
        lab2=tk.Label(text="ID", font=(",30))
        lab2.place(x=20,y=120)
        lab3=tk.Label(text="item name", font=(",30))
        lab3.place(x=20,y=190)
        lab4=tk.Label(text="quantity", font=(",30))
        lab4.place(x=20,y=260)
        lab5=tk.Label(text="Register", font=(",30))
        lab5.place(x=20,y=330)

        txt1 = tk.Entry (font=(", 30), width=15)
        txt1.place(x=200,y=120)
        txt2=tk.Entry(font=(",30), width=15)
        txt2.place (x=200, y=190)
        txt3=tk.Entry(font=(",30), width=15)
        txt3.place (x=200, y=260)
        txt4 = tk.Entry (font=(", 30), width=15)
        txt4.place (x=200, y=330)

        bot1=tk.Button(lt, text="Registration", font=(",40), width=5, command=bot1_1)
        bot1.place(x=120,y=450)
        bot2=tk.Button(lt, text="End", font=(",40), width=5, command=exit_1)
        bot2.place(x=320,y=450)

        lt.mainloop()


s1 = file1_1()
s1.file1_2()

Executed File Contents

ID, item name, quantity, subscriber
0 1, test 1, 1, Masaya

python csv

2022-09-30 19:41

1 Answers

There seems to be a lot of things to do with the program configuration, but writing the data you entered into the file should be working properly.

The file is written to correspond to the data entered, and the subscriber data exists (if entered).

As you wrote in the comment, 01 was entered in the ID field with spaces between them, so it is believed that it was written in the csv file.There is a data called masaya in the subscriber section of the questionnaire.

For example, if you leave the subscriber field blank and click the "Register" button, it will certainly be written without any data.

If you have limitations or specifications (minimum maximum digits, inputable character types/string/format, etc.) on your data, check the format before writing to the file.

Or, if you look at the file in Excel or go through access or database registration programs, are you experiencing data loss?

In other words, in what situations and means was "Data deviates from the label and there is no ""registrant"" data" confirmed?"That's right.

If so, add it to the questionnaire as part of the problem.

At the moment, the possibility is that the new line code of the file OS prepared as a label (header) line on Linux/MacOS is LF, not CRLF, and the software that reads the results checks the new line code specification (CRLF).


2022-09-30 19:41

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.