def lib_log(): log=raw_input("\nMemeber ID:\n") password=getpass.getpass() f=open("/Python27/libr/librarians.txt") g=0 while True: a=f.readline() if(len(a)==0): break mem=eval(a) if (mem[0]==log and mem[1]==password): g=1 break if g==0: print("\nInvalid user ID or Password\n") sup_a=raw_input("\n1.Retry\nany other key to go back") if sup_a=='1': os.system('cls') welcome.func() lib_log() else: os.system('cls') main() else: librarian.main1()
def main(x): os.system('cls') welcome.func() print("\nSearch based on the following attributes:-\n") inp = input( "\n1.Author name and Book Title[Recommended]\n\n2.Author name\n\n3.BookTitle\n\n4.Book Category\n\n5.Back\n\n6.Exit" ) if inp == '1': main1(x) elif inp == '2': main2(x) elif inp == '3': main3(x) elif inp == '4': main4(x) elif inp == '5': if (x == 1): os.system('cls') librarian.main1() else: os.system('cls') librarian.main2() elif inp == '6': sys.exit() else: print "\nTry again\n" main(x)
def main(x): os.system('cls') welcome.func() print("\nSearch based on the following attributes:-\n") inp=raw_input("\n1.Author name and Book Title[Recommended]\n\n2.Author name\n\n3.BookTitle\n\n4.Book Category\n\n5.Back\n\n6.Exit") if inp=='1': main1(x) elif inp=='2': main2(x) elif inp=='3': main3(x) elif inp=='4': main4(x) elif inp=='5': if (x==1): os.system('cls') librarian.main1() else: os.system('cls') librarian.main2() elif inp=='6': sys.exit() else: print "\nWrong choice\n" main(x)
def main1(x): os.system('cls') welcome.func() aut=raw_input("\nType the author name with alteast 3 characters\n") if len(aut)<3: print("\nToo less Characters for an efficient searching...\nTry again") main1(x) tit=raw_input("\nType the book title with alteast 3 characters\n") if len(tit)<3: print("Too less Characters for an efficient searching...Try again") main1(x) f=open("/Python27/libr/books.txt") flag=0 while True: os.system('cls') welcome.func() w=f.readline() if(len(w)==0): break b=eval(w) if(b[3].find(aut)!=-1 and b[1].find(tit)!=-1 and b[8]=='#'): print "\nBook Available in the library\n" "\nBook Serial no ="+b[0]+"\nBook Title ="+b[1]+"\nCategory ="+b[2]+"\nBook Author ="+b[3]+"\nBook Edition ="+str(b[5])+"\nBook Publisher ="+str(b[7]) inp1=raw_input("\nIs this the book which you where looking for?\nPress 1 for yes else any other key to continue searching\n") if inp1=='1': flag=1 break elif(b[3].find(aut)!=-1 and b[1].find(tit)!=-1 and b[8]!='#'): print "\nBook is present in the library but has been allocated to some one else\n" inp1=raw_input("\nTo stop searching press 1\n else any other key to continue searching\n") if inp1=='1': flag=1 break else: main(x) f.close() if(flag==0): q=raw_input("\n\nSorry\nThere are no books available based on your query\nPress 1 to Try Again \nAny other key to go back\n") if(q=='1'): main1(x) else: if (x==1): os.system('cls') librarian.main1() else: os.system('cls') librarian.main2() elif(flag==1): if (x==1): os.system('cls') librarian.main1() else: os.system('cls') librarian.main2()
def main4(x): os.system('cls') welcome.func() cat = input("\nType the category(minimum 5 characters)\n") if len(cat) < 5: print("Too few characters for an efficient search...Try again") main4(x) f = open( "C:/Users/Administrator/Documents/Python Scripts/Library/books.txt") flag = 0 while True: os.system('cls') welcome.func() w = f.readline() if (len(w) == 0): break b = eval(w) if (b[2].find(cat) != -1 and b[8] == '#'): print "\n\nBook Available\n" "\nBook Serial no =" + b[ 0] + "\nBook Title =" + b[1] + "\nCategory =" + b[ 2] + "\nBook Author =" + b[3] + "\nBook Edition =" + str( b[5]) + "\nBook Publisher =" + str(b[7]) inp1 = input( "\n\nIs this the book which you where looking for?\nPress 1 for yes \nAny other key to continue searching\n" ) if inp1 == '1': flag = 1 break f.close() if (flag == 0): q = input( "\nSorry\nThere are no books available based on your query\nPress 1 to Try Again or any other key to go back\n" ) if (q == '1'): main4(x) else: if (x == 1): os.system('cls') librarian.main1() else: os.system('cls') librarian.main2() elif (flag == 1): if (x == 1): os.system('cls') librarian.main1() else: os.system('cls') librarian.main2()
def main(x): os.system('cls') welcome.func() flag=0 f=open("/Python27/libr/stud_db1.txt") g=open("/Python27/libr/students_list_with_fine.txt","w") g.write("USN FINE\n") l=[] while True: w=f.readline() if(len(w)==0): break d=eval(w) for k in d: for i in [0,1,2]: if d[k][i][0]!='#': d[k][3]+=1000 d[k][i][0]='#' d[k][i][1]='@' if d[k][3]>0: flag=1 g.write(k+" "+"Rs."+str(d[k][3])) print("\n"+k+" "+"Rs."+str(d[k][3])) d[k][3]=0 l.append(d) f.close() if flag==0: print("None of the students have any fine\n") else: print("\nOpen the file 'students_list_with_fine.txt' to get a hard copy of students who have fine") f=open("/Python27/libr/stud_db1.txt","w") f.write(str(l[0])) for i in l[1:]: f.write("\n"+str(i)) g.close() q=raw_input("1 to go back or any other key to exit") if(q=='1'): if (x==1): os.system('cls') librarian.main1() else: os.system('cls') librarian.main2() else: sys.exit()
def main4(x): os.system('cls') welcome.func() cat=raw_input("\nType the category(minimum 5 characters)\n") if len(cat)<5: print("Too less Characters for an efficient searching...Try again") main4(x) f=open("/Python27/libr/books.txt") flag=0 while True: os.system('cls') welcome.func() w=f.readline() if(len(w)==0): break b=eval(w) if(b[2].find(cat)!=-1 and b[8]=='#'): print "\n\nBook Available\n" "\nBook Serial no ="+b[0]+"\nBook Title ="+b[1]+"\nCategory ="+b[2]+"\nBook Author ="+b[3]+"\nBook Edition ="+str(b[5])+"\nBook Publisher ="+str(b[7]) inp1=raw_input("\n\nIs this the book which you where looking for?\nPress 1 for yes \nAny other key to continue searching\n") if inp1=='1': flag=1 break f.close() if(flag==0): q=raw_input("\nSorry\nThere are no books available based on your query\nPress 1 to Try Again or any other key to go back\n") if(q=='1'): main4(x) else: if (x==1): os.system('cls') librarian.main1() else: os.system('cls') librarian.main2() elif(flag==1): if (x==1): os.system('cls') librarian.main1() else: os.system('cls') librarian.main2()
def main(x): lis = [] f = open( "C:/Users/Administrator/Documents/Python Scripts/Library/books.txt", "r") while True: l = f.readline() if (len(l) == 0): break m = eval(l) lis.append(m) id = m[0] f.close() q = list(id) s1 = q[5] s1 = int(s1) s2 = q[4] s2 = int(s2) s3 = q[3] s3 = int(s3) s = s1 + (10 * s2) + (100 * s3) s = s + 1 if (s <= 9): q[5] = str(s) elif (s <= 99): a = s % 10 q[5] = a s = s / 10 q[4] = s else: q[5] = s % 10 s = s / 10 q[4] = s % 10 s = s / 10 q[3] = s s1 = ''.join(str(n) for n in q) print s1 n = 0 while (n == 0): try: b_n = input("\nenter book name\n") b_c = input("\nenter category\n") b_a = input("\nenter author\n") b_p = input("\nenter price\n") b_e = input("\nenter edition\n") b_y = input("\nenter year\n") b_pu = input("\nenter publisher\n") n = 1 except SyntaxError: print "wrong Input" n = 0 except: print "wrong Input" n = 0 l = [s1, b_n, b_c, b_a, b_p, b_e, b_y, b_pu, '#'] lis.append(l) f.close() f = open( "C:/Users/Administrator/Documents/Python Scripts/Library/books.txt", "w") f.write(str(lis[0])) for i in lis[1:]: f.write("\n" + str(i)) print("\nBook added Succesfully\n") f.close() a = raw_input("\nTo Add Another book Enter 1\npress any key to go back\n") if a == '1': main(x) else: if (x == 1): os.system('cls') librarian.main1() else: os.system('cls') librarian.main2()
def main(x): os.system('cls') welcome.func() f=open("/Python27/libr/stud_db1.txt") g=open("/Python27/libr/list_fin1.txt","w") g.write("STUDENT USN BOOKS TO BE RETURNED\n") newlist=[] flag=0 while True: pending='' lis=[] w=f.readline() if len(w)==0: break dic=eval(w) for k in dic: for i in [0,1,2]: if dic[k][i][0]!='#': lis.append(dic[k][i][0]) if str(lis)!='': pending=str(lis) if pending!='': g.write(k+" "+pending+"\n") f.close() g.close() da1 =raw_input('Enter the final fine evaluation date(dd/mm/yyyy):') try: date2 = time.strptime(da1, '%d/%m/%Y') #convert string into date except ValueError: print('Invalid date!\nEnter again') main() d=da1.split('/') #for extracting date,year and month from the date1 d1='' for i in d: d1=d1+i #print d1 s2 =datetime.datetime.strptime(d1,'%d%m%Y').date() s1=datetime.date.today() if s2<s1: print("\nYou have typed a date which is already over...Type a valid date\n") main(x) os.system('cls') f=open("/Python27/libr/list_fin1.txt") print("\nThe following students are here by informed to return the books mentioned along with their USN on or before "+da1+"\n\nStudents who fail to return any books before mentioend date will have to pay the fine of Rs1000 in order to get the hall ticket\n") while True: w=f.readline() if (len(w)==0): break print ("\n"+w) f.close() print("\nOpen the file 'list_fin1.txt' to get a hard copy of students who are supposed to return books\n") print("\n\nInstruction for the librarians:\nPlease calculate the fine after date: "+da1+" so that students can get time to return their due books") q=raw_input("1 to go back or any other key to exit") if(q=='1'): if (x==1): os.system('cls') librarian.main1() else: os.system('cls') librarian.main2() else: sys.exit()
def main1(x): os.system('cls') welcome.func() aut = input("\nType the author name with at least 3 characters\n") if len(aut) < 3: print("\nToo few characters for an efficient search...\nTry again") main1(x) titl = input("\nType the book title with at least 3 characters\n") if len(titl) < 3: print("Too few characters for an efficient search...Try again") main1(x) f = open( "C:/Users/Administrator/Documents/Python Scripts/Library/books.txt") flag = 0 while True: os.system('cls') welcome.func() w = f.readline() if (len(w) == 0): break b = eval(w) if (b[3].find(aut) != -1 and b[1].find(titl) != -1 and b[8] == '#'): print "\nBook available in the library\n" "\nBook Serial no =" + b[ 0] + "\nBook Title =" + b[1] + "\nCategory =" + b[ 2] + "\nBook Author =" + b[3] + "\nBook Edition =" + str( b[5]) + "\nBook Publisher =" + str(b[7]) inp1 = input( "\nIs this the book which you where looking for?\nPress 1 for yes or any other key to continue searching\n" ) if inp1 == '1': flag = 1 break elif (b[3].find(aut) != -1 and b[1].find(titl) != -1 and b[8] != '#'): print "\nBook is present in the library but has been allocated to some one else\n" inp1 = input( "\nTo stop searching press 1\n otherwise press any other key to continue searching\n" ) if inp1 == '1': flag = 1 break else: main(x) f.close() if (flag == 0): q = input( "\n\nSorry\nThere are no books available based on your query\nPress 1 to Try Again \nAny other key to go back\n" ) if (q == '1'): main1(x) else: if (x == 1): os.system('cls') librarian.main1() else: os.system('cls') librarian.main2() elif (flag == 1): if (x == 1): os.system('cls') librarian.main1() else: os.system('cls') librarian.main2()
def main(bid, d1, x): f = open( "C:/Users/Administrator/Documents/Python Scripts/Library/books.txt") flag = 0 newlines = [] while True: w = f.readline() if (len(w) == 0): break b = eval(w) if (b[0] == bid and b[8] != '#'): book_cost = b[4] flag = 1 break newlines.append(b) usn = b[8] b[8] = '#' newlines.append(b) while True: q = f.readline() if len(q) == 0: break q1 = eval(q) newlines.append(q1) f.close() f = open( "C:/Users/Administrator/Documents/Python Scripts/Library/books.txt", "w") f.write(str(newlines[0])) for k in newlines[1:]: f.write("\n" + str(k)) f.close() newlines = [] f = open( "C:/Users/Administrator/Documents/Python Scripts/Library/member_db1.txt" ) while True: w = f.readline() if (len(w) == 0): break dic = eval(w) if dic.has_key(usn): for i in dic[usn]: if i[0] == bid: d1 = datetime.date.today() # date of return # date of issue i[1] = str(i[1]) d2 = i[1].split('-') d3 = '' for h in d2: d3 = d3 + h d4 = datetime.datetime.strptime(d3, '%Y%m%d').date() d5 = d1 - d4 if d5 == datetime.timedelta(0): days = 0 else: days = int(str(d5).split()[0]) if (days > 15): print("\nMember has a fine of " + str(days - 15)) dic[usn][3] += (days - 15) i[0] = '#' i[1] = '@' flag = 1 break break newlines.append(dic) newlines.append(dic) while True: w = f.readline() if (len(w) == 0): break dic = eval(w) newlines.append(dic) f.close() f = open( "C:/Users/Administrator/Documents/Python Scripts/Library/member_db1.txt", "w") f.write(str(newlines[0])) for k in newlines[1:]: f.write("\n" + str(k)) f.close() print "\nThe book has been returned\n" vv = input("1 to go back or any other key to exit") if (vv == '1'): if (x == 1): os.system('cls') librarian.main1() else: os.system('cls') librarian.main2() else: sys.exit()
def main(x): os.system('cls') welcome.func() sid = input("Enter the book ID to be reissued") f = open( "C:/Users/Administrator/Documents/Python Scripts/Library/books.txt") flag = 0 l = [] usn = '0' while True: w = f.readline() if (len(w) == 0): break b = eval(w) if (b[0] == sid and b[8] != '#'): flag = 1 usn = b[8] if flag == 0: f.close() print("This book has never been issued or wrong book ID") inp = input( "\nPress 1 to type the book ID again\nAny other key to go back") if (inp == '1'): main(x) else: if (x == 1): os.system('cls') librarian.main1() else: os.system('cls') librarian.main2() f.close() print("\nThe book has beeen reissued\n") g = open( "C:/Users/Administrator/Documents/Python Scripts/Library/member_db1.txt" ) while True: w = g.readline() if (len(w) == 0): break dic = eval(w) if dic.has_key(usn): for i in dic[usn]: if (isinstance(i, int) == False): if i[0] == sid: d1 = datetime.date.today() # date of return i[1] = str(i[1]) # date of issue d2 = i[1].split('-') d3 = '' for h in d2: d3 = d3 + h d4 = datetime.datetime.strptime(d3, '%Y%m%d').date() d5 = d1 - d4 #print d5 if d5 == datetime.timedelta(0): days = 0 else: days = int(str(d5).split()[0]) if (days > 15): print("\nStudent has a fine of " + str(days - 15)) dic[usn][3] += (days - 15) i[1] = str(d1) l.append(str(dic)) g.close() h = open( "C:/Users/Administrator/Documents/Python Scripts/Library/member_db1.txt", "w") h.write(l[0]) for i in l[1:]: h.write("\n" + i) h.close() q = input("\n1 to go back or any other key to exit") if (q == '1'): if (x == 1): os.system('cls') librarian.main1() else: os.system('cls') librarian.main2() else: sys.exit()
def main(x): os.system('cls') welcome.func() f=open("/Python27/libr/stud_db1.txt") flag=0 line_count=-1 newlines=[] #to store the lines until specified usn is found usn=raw_input("\nEnter the USN\n") while True: line=f.readline() # read a line from student database if len(line)==0: break line_count+=1 dic=eval(line) #convert it into dictionary newlines.append(dic) if dic.has_key(usn): # check if the read usn exists flag=1 break if flag==0: print"\nInvalid USN\n" inp=raw_input("\nPress 1 to type again or anything else to go back\n") if inp=='1': os.system('cls') main(x) else: if (x==1): os.system('cls') librarian.main1() else: os.system('cls') librarian.main2() space=-1 count=0 for i in dic[usn]: check=isinstance( i, int ) if check==True: i=str(i) space+=1 #i is status of 3 slots of books to each usn if i[0]=='#': break else: count+=1 #print space if count==4: v=raw_input("\n\nYou have already issued 3 books\n\nPress 1 to go back\n\nelse anything else to exit\n") if v=='1': if (x==1): os.system('cls') librarian.main1() else: os.system('cls') librarian.main2() else: sys.exit() else: flag_1=0 line_count2=-1 newlines2=[] sid=raw_input("\nType the book ID\n") g=open("/Python27/libr/books.txt") while True: w=g.readline() if(len(w)==0): break line_count2+=1 b=eval(w) if(b[0]==sid and b[8]=='#'): flag_1=1 print "\n\nBook Allocated\n" "\nBook Serial no ="+b[0]+"\nBook Title ="+b[1]+"\nCategory ="+b[2]+"\nBook Author ="+b[3]+"\nBook Edition ="+str(b[5])+"\nBook Publisher ="+str(b[7]) d2 = datetime.date.today()+ datetime.timedelta(days=15) print("\nReturn Date : "+str(d2)) break newlines2.append(b) if flag_1==0: inpu_2=raw_input("No book available with this book ID in the library\nPress1.to go back\nelse any other key to exit") if inpu_2=='1': if (x==1): os.system('cls') librarian.main1() else: os.system('cls') librarian.main2() else: sys.exit() if flag_1==1: b[8]=usn newlines2.append(b) while True: q=g.readline() if len(q)==0: break q1=eval(q) newlines2.append(q1) g.close() usn_line=newlines[line_count] #print line_count #for z in range(0,line_count): #for testing # print newlines[z] #for testing #print usn_line #get the line to be changed x=usn_line[usn] #get the key value of that line x[space][0]=sid d1=datetime.date.today() x[space][1]=str(d1) while True: q=f.readline() if len(q)==0: break q1=eval(q) newlines.append(q1) f.close() g=open('/Python27/libr/books.txt',"w") g.write(str(newlines2[0])) for i in newlines2[1:]: g.write("\n"+str(i)) g.close() f=open('/Python27/libr/stud_db1.txt',"w") f.write(str(newlines[0])) for i in newlines[1:]: f.write("\n"+str(i)) f.close() inpu_2=raw_input("\nPress1.to go back\nelse any other key to exit") if inpu_2=='1': if (x==1): os.system('cls') librarian.main1() else: os.system('cls') librarian.main2() else: sys.exit()
def main(x): os.system('cls') welcome.func() f = open( "C:/Users/Administrator/Documents/Python Scripts/Library/member_db1.txt" ) flag = 0 line_count = -1 newlines = [] #to store the lines until specified usn is found usn = input("\nEnter the USN\n") while True: line = f.readline() # read a line from student database if len(line) == 0: break line_count += 1 dic = eval(line) #convert it into dictionary newlines.append(dic) if dic.has_key(usn): # check if the read usn exists flag = 1 break if flag == 0: print "\nInvalid USN\n" inp = input("\nPress 1 to type again or anything else to go back\n") if inp == '1': os.system('cls') main(x) else: if (x == 1): os.system('cls') librarian.main1() else: os.system('cls') librarian.main2() space = -1 count = 0 for i in dic[usn]: check = isinstance(i, int) if check == True: i = str(i) space += 1 #i is status of 3 slots of books to each usn if i[0] == '#': break else: count += 1 #print space if count == 4: v = input( "\n\nYou have already issued 3 books\n\nPress 1 to go back\n\n press anything else to exit\n" ) if v == '1': if (x == 1): os.system('cls') librarian.main1() else: os.system('cls') librarian.main2() else: sys.exit() else: flag_1 = 0 line_count2 = -1 newlines2 = [] sid = input("\nType the book ID\n") g = open( "C:/Users/Administrator/Documents/Python Scripts/Library/books.txt" ) while True: w = g.readline() if (len(w) == 0): break line_count2 += 1 b = eval(w) if (b[0] == sid and b[8] == '#'): flag_1 = 1 print "\n\nBook Allocated\n" "\nBook Serial no =" + b[ 0] + "\nBook Title =" + b[1] + "\nCategory =" + b[ 2] + "\nBook Author =" + b[ 3] + "\nBook Edition =" + str( b[5]) + "\nBook Publisher =" + str(b[7]) d2 = datetime.date.today() + datetime.timedelta(days=15) print("\nReturn Date : " + str(d2)) break newlines2.append(b) if flag_1 == 0: inpu_2 = input( "No book available with this book ID in the library\nPress1.to go back\npress any other key to exit" ) if inpu_2 == '1': if (x == 1): os.system('cls') librarian.main1() else: os.system('cls') librarian.main2() else: sys.exit() if flag_1 == 1: b[8] = usn newlines2.append(b) while True: q = g.readline() if len(q) == 0: break q1 = eval(q) newlines2.append(q1) g.close() usn_line = newlines[line_count] #print line_count #for z in range(0,line_count): #for testing # print newlines[z] #for testing #print usn_line #get the line to be changed x = usn_line[usn] #get the key value of that line x[space][0] = sid d1 = datetime.date.today() x[space][1] = str(d1) while True: q = f.readline() if len(q) == 0: break q1 = eval(q) newlines.append(q1) f.close() g = open( 'C:/Users/Administrator/Documents/Python Scripts/Library/books.txt', "w") g.write(str(newlines2[0])) for i in newlines2[1:]: g.write("\n" + str(i)) g.close() f = open( 'C:/Users/Administrator/Documents/Python Scripts/Library/member_db1.txt', "w") f.write(str(newlines[0])) for i in newlines[1:]: f.write("\n" + str(i)) f.close() inpu_2 = input("\nPress1.to go back\nPress any other key to exit") if inpu_2 == '1': if (x == 1): os.system('cls') librarian.main1() else: os.system('cls') librarian.main2() else: sys.exit()
def main(x): os.system('cls') welcome.func() f = open( "C:/Users/Administrator/Documents/Python Scripts/Library/member_db1.txt" ) g = open( "C:/Users/Administrator/Documents/Python Scripts/Library/list_fin1.txt", "w") g.write("STUDENT USN BOOKS TO BE RETURNED\n") newlist = [] flag = 0 while True: pending = '' lis = [] w = f.readline() if len(w) == 0: break dic = eval(w) for k in dic: for i in [0, 1, 2]: if dic[k][i][0] != '#': lis.append(dic[k][i][0]) if str(lis) != '': pending = str(lis) if pending != '': g.write(k + " " + pending + "\n") f.close() g.close() da1 = input('Enter the final fine evaluation date(dd/mm/yyyy):') try: date2 = time.strptime(da1, '%d/%m/%Y') #convert string into date except ValueError: print('Invalid date!\nEnter again') main() d = da1.split('/') #for extracting date,year and month from the date1 d1 = '' for i in d: d1 = d1 + i #print d1 s2 = datetime.datetime.strptime(d1, '%d%m%Y').date() s1 = datetime.date.today() if s2 < s1: print( "\nYou have typed a date which is already over...Type a valid date\n" ) main(x) os.system('cls') f = open( "C:/Users/Administrator/Documents/Python Scripts/Library/list_fin1.txt" ) print( "\nThe following students are here by informed to return the books mentioned along with their USN on or before " + da1 + "\n\nStudents who fail to return any books before mentioend date will have to pay the fine of Rs1000 in order to get the hall ticket\n" ) while True: w = f.readline() if (len(w) == 0): break print("\n" + w) f.close() print( "\nOpen the file 'list_fin1.txt' to get a hard copy of students who are supposed to return books\n" ) print( "\n\nInstruction for the librarians:\nPlease calculate the fine after date: " + da1 + " so that students can get time to return their due books") q = input("1 to go back or any other key to exit") if (q == '1'): if (x == 1): os.system('cls') librarian.main1() else: os.system('cls') librarian.main2() else: sys.exit()
def main(bid,d1,x): f=open("/Python27/libr/books.txt") flag=0 newlines=[] while True: w=f.readline() if(len(w)==0): break b=eval(w) if(b[0]==bid and b[8]!='#'): book_cost=b[4] flag=1 break newlines.append(b) usn=b[8] b[8]='#' newlines.append(b) while True: q=f.readline() if len(q)==0: break q1=eval(q) newlines.append(q1) f.close() f=open("/Python27/libr/books.txt","w") f.write(str(newlines[0])) for k in newlines[1:]: f.write("\n"+str(k)) f.close() newlines=[] f=open("/Python27/libr/stud_db1.txt") while True: w=f.readline() if(len(w)==0): break dic=eval(w) if dic.has_key(usn): for i in dic[usn]: if i[0]==bid: d1=datetime.date.today()# date of return # date of issue i[1]=str(i[1]) d2=i[1].split('-') d3='' for h in d2: d3=d3+h d4=datetime.datetime.strptime(d3, '%Y%m%d').date() d5=d1-d4 if d5==datetime.timedelta(0): days=0 else: days=int(str(d5).split()[0]) if(days>15): print("\nStudent has a fine of "+str(days-15)) dic[usn][3]+=(days-15) i[0]='#' i[1]='@' flag=1 break break newlines.append(dic) newlines.append(dic) while True: w=f.readline() if(len(w)==0): break dic=eval(w) newlines.append(dic) f.close() f=open("/Python27/libr/stud_db1.txt","w") f.write(str(newlines[0])) for k in newlines[1:]: f.write("\n"+str(k)) f.close() print "\nThe book has been returned\n" vv=raw_input("1 to go back or any other key to exit") if(vv=='1'): if (x==1): os.system('cls') librarian.main1() else: os.system('cls') librarian.main2() else: sys.exit()