Python Forum
I can't write my data to the data file , Why?
Thread Rating:
  • 1 Vote(s) - 4 Average
  • 1
  • 2
  • 3
  • 4
  • 5
I can't write my data to the data file , Why?
#5
(Jan-08-2019, 10:43 PM)Gribouillis Wrote:
Quote:When I delete it still doesnt work
Try to print() in the console instead of writing to file. Once it works with print(), replace print() with fout.write()


all code like that
def sorunvar ():
    print ("?al?sanlar haftada 45 saatten fazla cal?smamal?d?r mesai ?creti odemel?s?n?z.")

def sorunyok ():
    print ("?al?sma saat?nde sorun yok")


# 1 e t?klayarak g?r?s yap?yoruz cal?sanlarla ?lg?l? 2 de ve 3 de de ayr? ayr? seyler hesaplan?yor 6 ya t?klay?nca duruyor.

menu = 0
while menu != 7:
    try:
        cevap = str(menu)

        menu = int(input("giris yapmak icin 1e \n toplam saati hesaplamak icin 2ye,\n butun cal?sanlar?n toplam maas?n? hesaplamak icin 3 e,\n izin g?nleri i?in 4 e\n 45 saat cezas?n? hesaplamak icin 5 e t?klay?n?z\n bitirmek i?in7ya"))
    except(SyntaxError,NameError):
        print "1 den 7 ye kadar giriniz"
    if menu == 1:
        fin = "data.txt"
        fout = open(fin,'a')
        info = ""
        no = 0
        while info != "no":
            info = raw_input("Veri girmek istiyor musunuz? (yes/no)")
            if info != "no" and info == "yes":
                try:
                    no = no + 1
                    weekdays1 = int(input("09:00-17:00-pazartesi"))
                    weekdays1_2= int (input("17:00-09:00-pazartesi"))
                    weekdays2 = int(input("09:00-17:00-sali"))
                    weekdays2_2= int (input("17:00-09:00-sali"))

                    weekdays3 = int(input("09:00-17:00-carsamba"))
                    weekdays3_2= int (input("17:00-09:00-carsamba"))
                    weekdays4 = int(input("09:00-17:00-persembe"))
                    weekdays4_2= int (input("17:00-09:00-persembe"))
                    weekdays5 = int(input("09:00-17:00-cuma"))
                    weekdays5_2= int (input("17:00-09:00-cuma"))
                    weekend6 = int(input("09:00-17:00-cumartesi"))
                    weekend6_2 =int (input("17:00-09:00-cumartesi"))
                    weekend7 = int(input("09:00-17:00-pazar"))
                    weekend7_2 =int (input("17:00-09:00-pazar"))



                    totalweekdayshour = (weekdays1 + weekdays2 + weekdays3 + weekdays4 + weekdays5+ weekdays1_2+weekdays2_2+weekdays3_2+weekdays4_2+weekdays5_2)
                    totalweekendhour = (weekend6 + weekend7 + weekend6_2 + weekend7_2)

                    totalhour = totalweekdayshour + totalweekendhour
                    # hafta i?i sabah normal maas, hafta i?i ak?am 1.5 kat? haftasonu 2 ,haftasonu aksam 2.5 kat? maas al?n?r.
                    n = int(input("saatlik kazanc"))


                    m1 = (weekdays1) * n
                    m1_2 = ((weekdays1_2) * n)* 1.5

                    m2 = (weekdays2) * n
                    m2_2 = ((weekdays1_2) * n)* 1.5

                    m3 = (weekdays3 ) * n
                    m3_2 = ((weekdays1_2) * n)* 1.5
                    m4 = (weekdays4 ) * n
                    m4_2 = ((weekdays1_2) * n)* 1.5
                    m5 = (weekdays5 ) * n
                    m5_2 = ((weekdays1_2) * n)* 1.5

                    m6 = (weekend6)* 2 * n
                    m6_2 = ((weekdays1_2) * n)* 2.5
                    m7 = (weekend7) *(2* n)
                    m7_2 = ((weekdays1_2) * n)* 2.5

                    totalsalary = m1+m1_2+m2+m2_2+m3+m3_2+m4+m4_2+m5+m5_2+m6+m6_2+m7+m7_2

                    if weekdays1 >= 9 :
                        if weekdays1_2 >= 9 :
                           if weekdays2 >= 9 :
                              if weekdays2_2 >= 9 :
                                 if weekdays3 >= 9 :
                                    if weekdays3_2 >= 9 :
                                        if weekdays3 >= 9 :
                                            if weekdays3_2 >= 9 :
                                                if weekdays4 >= 9 :
                                                    if weekdays4_2 >= 9 :
                                                         if weekdays5 >= 9 :
                                                            if weekdays5_2 >= 9 :


                                                                 print ("Hatali calisma saati girisi degerler?n?z kayded?lmed?")
                except(SyntaxError,NameError,IndexError):
                    print("Oops! Enter a number.")

                    break
                    fout.write("%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s \n" % (no, weekdays1,weekdays1_2,weekdays2,weekdays2_2,weekdays3,weekdays3_2,weekdays4,weekdays4_2,weekdays5,weekdays5_2,weekend6,weekend6_2,weekend7,weekend7_2,totalweekdayshour,totalweekendhour,totalhour,totalsalary))
                    fout.close()
#toplam saat? veriyor her bir ?al?san i?in
    elif menu ==2:
        print "2. Selection"
        fin = open("data.txt", "r")
        for line in fin:
            mylist = list(line.split(","))
            no=mylist[0]
            totalweekdayshour=mylist[8]
            totalweekendhour=mylist[9]
            totalhour=mylist[10]
            print 'No : ', no
            print 'Total hour : ', totalhour
            print 'Hafta ici cal?sma saatleri: ', totalweekdayshour
            print 'Hafta sonu cal?sma saatleri: ', totalweekendhour
            print ""
        fin.close()
# .. ama yapmas? gereken her bir ?al?san?n maas?n? toplay?p g?der? hesaplamak
    elif menu == 3:
        fin = open("data.txt","r")
        totalexpence= []
        totalsalary=[]
        i = 0
        a1=0
        for line in fin:
            appendline(totalexpence)
            a1 = a1 + float(totalexpence[i][8])
            i = i + 1

        fin.close

        print ("Total expence:", a1)
        print ""
#?alisan?n ka? gun izin yapt?g?n? ve izin g?nlerini yazan bir program
#bu bozuk yapab?l?rsen?z g?zel olur.
    elif menu ==4:
        print "2. Selection"
        fin = open("data.txt", "r")
        for line in fin:
            mylist = list(line.split(","))
            no=mylist[0]
            totalweekdayshour=mylist[8]
            totalweekendhour=mylist[9]
            totalhour=mylist[10]
            print 'No : ', no
            print 'Total hour : ', totalhour
            print 'Hafta ici cal?sma saatleri: ', totalweekdayshour
            print 'Hafta sonu cal?sma saatleri: ', totalweekendhour
            print ""
        fin.close()
#45 saatten fazla cal?sma yasas?.......
    elif menu ==5 :
        bronk=open("data.txt","r")
        i=0
        totalweekdayshour=[]
        totalweekendhour=[]
        kk=0
        for line in bronk:

            appendline(totalweekdayshour)
            appendline(totalweekendhour)
            kk =float(totalweekdayshour[i][5]) + float(totalweekendhour[i][6])
            i=i+1
        if kk >= 45 :
            sorunvar()

        else:
            kk<= 45
            sorunyok()

        bronk.close

    elif menu == 6:
        kronk= open("data.txt","r")
        totalsalary=[]
        no=[]
        i=0
        for line in kronk:

            appendline(totalsalary)
            appendline(no)
            kk=totalsalary[i][8]
            nn=int(no[i][0])
            i=i+1

            print nn,kk
Reply


Messages In This Thread
RE: I can't write my data to the data file , Why? - by canatilaa - Jan-08-2019, 10:50 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  What does .flush do? How can I change this to write to the file? Pedroski55 3 271 Apr-22-2024, 01:15 PM
Last Post: snippsat
  encrypt data in json file help jacksfrustration 1 268 Mar-28-2024, 05:16 PM
Last Post: deanhystad
  Help with to check an Input list data with a data read from an external source sacharyya 3 441 Mar-09-2024, 12:33 PM
Last Post: Pedroski55
  Last record in file doesn't write to newline gonksoup 3 472 Jan-22-2024, 12:56 PM
Last Post: deanhystad
  write to csv file problem jacksfrustration 11 1,595 Nov-09-2023, 01:56 PM
Last Post: deanhystad
  python Read each xlsx file and write it into csv with pipe delimiter mg24 4 1,525 Nov-09-2023, 10:56 AM
Last Post: mg24
  Input network device connection info from data file edroche3rd 6 1,096 Oct-12-2023, 02:18 AM
Last Post: edroche3rd
  Convert File to Data URL michaelnicol 3 1,233 Jul-08-2023, 11:35 AM
Last Post: DeaD_EyE
  How do I read and write a binary file in Python? blackears 6 6,885 Jun-06-2023, 06:37 PM
Last Post: rajeshgk
Video doing data treatment on a file import-parsing a variable EmBeck87 15 2,978 Apr-17-2023, 06:54 PM
Last Post: EmBeck87

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020