[Python] add data to specific row and colum in csv python

Discussão em 'Python' iniciado por Stack, Novembro 29, 2024.

  1. Stack

    Stack Membro Participativo

    I have this code which I want to add data from the user input to each column and rows:

    import csv
    import datetime
    import calendar

    days = [i for i in range(1,32,1)]
    days = (','.join(map(str,days))).strip() # To remove square brackets
    field = ['fingerprint', 'month', 'year',days]

    for i in range(4):
    finger1 = input("input the fingerprints: ")
    finger = ''.join(finger1)
    year = input("Enter Year")
    month = input("enter month")


    def main():
    with open('shoft.csv', 'w', newline='') as file:
    add = csv.writer(file, quoting=csv.QUOTE_NONE, escapechar='/')
    add.writerow(field)
    add.writerows(finger)

    def addRow():
    pass

    def addColumn():
    pass

    if __name__ == "__main__":
    main()


    As I want to ask for times for 4 users to add their fingerprint number then it adds them to fingerprint column in four rows, then add year which same for all four rows with month And for days it automatically adds x for one and 6 for next day except Fridays should be always x. days numbers it should be just number but couldn't find solution to remove quotes other than adding escapechar with slash.

    like this :

    code,month,year,1,2,3,4,5,6,..31
    c633,5 ,2024,x,6,x,6...
    c600,5 ,2024,6,x,6,x..


    I mean how I control it to tell the user input goes to specific row and column and adds data automatically to days column.

    Continue reading...

Compartilhe esta Página