Professional Documents
Culture Documents
newAge = "20"
result = ""
with open("file.txt") as f:
for line in f:
if line.lower().startswith( "mo," ):
list = line.split(', ')
list[2] = str( newAge )
line = ", ".join( list )
result += line + '\n'
f = open("file.txt", 'w') # should be in 'wt or 'w' mode
f.write(result)
f.close()
name = "Mahesha"
recordID =(int)(3)
after_update = ""
index = (int)(0)
with open("HardWareDetails.txt")as f:
for _ in range(recordID-1):
#index = index+1
print((str)(index))
if(index == (recordID-1)):
# print((str)(index)+"--------\n")
mylist =[]
mylist = line[index].split(',')
print(mylist)
mylist[3]= name
line = ','.join(mylist)
after_update=after_update+line+"\n"
else:
after_update=after_update+line+"\n"
print(after_update+"\n")
index = index+1
f2 = open("HardWareDetails.txt",'w')
f2.write(after_update)
f2.close()