I am looking for a solution for a code. I need to delete a section of writing in a file using python, the chunk is 5 lines here's an example.
Numberplate: BN30CWS
Time In: Time In: 11:11:3
Time Out: Time In: 11:11:51
Speed: Your Speed: 48MPH
Was this vechile speeding?: No
(Without the gaps )
So if i enter BN30CWS
i want those 5 lines to be deleted from the file (fileDocStandard) Please help, i have attempted making this working code for 4 hours now, and this is what i have come up with but it only deletes 1 line and wont delete the hole chunk
def deldata():
file = open(fileDocStandard, "r" )
array = []
for line in file:
array.append(line)
file.close()
for i in range(len(array)):
print (array[i])
let = input("Please enter the plate you want to delete ")
let = let.upper()
for i in range(len(array)):
arrayitem = array[i]
if (arrayitem[0]) == (let):
del (array[i])
break
file = open(fileDocStandard, "w")
file.close()
file = open(fileDocStandard, "a")
for i in range(len(array)):
file.write(array[i])
file.close()
Anyone see the issue, and can help me finally finish this?