I need to open a file for both reading and writing to a file. After reading some articles I fond that I can use the 'r+' mode. Here's what I want to achieve:
- Open the file and read data from it.
- Analyze and manipulate the data.
- Delete the contents of the file.
- Write new content to it.
But when I tried it, I got some weird outputs. Here are the screenshots:
First I tried this:
You'll notice that the data is appended(not what I wanted). So, I tried to truncate the file before writing to it:
Now, why am I getting those weird bytes at the start? Thanks.
PS I am on python 3.8.2 running on Windows 10.

