Hello.Please i have a problem with my code.I am trying to edit a file.The problem occurs when i use the seek function.for example,i have a file outlined like this:
myfile.txt
<Name>Ben</Name>
<Age>32</Age>
<Sex>Male</Sex>
<Country>Mars City</Country>
Now,when i try to edit the Age,i use the code:
f=open('myfile.txt','a')
f.seek(17,0)
f.write('<Age>1200</Age>')
f.close()
This code edits the Age but it ends up chopping off parts of the line
below it.Something like this:
myfile.txt
<Name>Ben</Name>
<Age>32</Age>Sex>Male</Sex>
<Country>Mars City</Country>
Please how do i edit the content of a file effectively.Is it a good idea to load the contents in a variable and manipulate it,what if i have over a billion bytes in the file?
Also,how do i delete from a file?
Thanks in advance