Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def writeStudent():
- with open("Student.txt" ,'a') as file :
- ch ='Y'
- while ch =='Y':
- Id=input('Enter the id : ')
- Name=input('Enter the name : ')
- Age=input('Enter the age : ')
- file.write(Id + '\t' + Name + '\t' + Age +'\n')
- ch = input('if u want to continue [ Y/N ] : ')
- def readStudent() :
- with open("Student.txt" ,'r' ) as file :
- print("Id\tName\tAge\n")
- for line in file :
- print(line , end='')
- def updateStudent() :
- import os
- ID=input('Enter the id for update its age :')
- with open("Student.txt" ,'r' ) as file :
- with open("StudentTemp.txt" , 'a') as temp :
- for line in file :
- L = line.split('\t')
- if ID==L[0] : ## this record
- Age= input('Enter the new age : ')
- L[2]= Age
- # line = L[0] + '\t' + L[1] + '\t' + L[2] + '\n'
- temp.write(L[0] + '\t' + L[1] + '\t' + L[2] + '\n' )
- os.remove("Student.txt")
- os.rename("StudentTemp.txt" ,"Student.txt")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement