Steven D'Aprano added the comment:
On Fri, Dec 25, 2020 at 01:31:51PM +, 施文峰 wrote:
> first test have a problem,you didn’t use r+ mode
I did, I copied your `test()` function exactly, however I did make a
mistake. I tried again with this:
>>> with open(FILE_PATH, 'r') as f:
... print(
施文峰 added the comment:
hi Steven
thanks for check my post
first test have a problem,you didn’t use r+ mode
step is
1. f.read
2. f.truncate(0)
3. f.write(something)
my test msg tell you
“
tell after delete content 33
content 0
tell after write 65
“
so you know after truncate f.tell =33
but
Steven D'Aprano added the comment:
You say:
> after process python3 test_case.py
> json file's content like this
>
> @@{"how_dare_you": "how_dare_you"}
I cannot replicate that result.
I created a "data.json" with the following content:
```
>>> with open(FILE_PATH, 'w') as f:
New submission from 施文峰 :
happen at io's reading & updating(r+) mode
after read,
file object's postion stay in last if you remove whole content ( truncate(0) ),
postion wil not back to 0 still stay in the last
then you start writing from last position(not 0)
that's why problem happen
test case c