[issue42733] [issue] io's r+ mode truncate(0)
Steven D'Aprano
report at bugs.python.org
Fri Dec 25 08:05:19 EST 2020
Steven D'Aprano <steve+python at pearwood.info> 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:
... f.write('{"how_dare_you": "how_dare_you"}\n')
...
33
>>> with open(FILE_PATH, 'r') as f:
... print(f.read())
...
{"how_dare_you": "how_dare_you"}
```
Then I ran your `test` function and the only result was to delete the newline at the end of the file:
```
>>> test()
beginning tell 0
tell after read 33
tell after delete content 33
content 0
tell after write 65
content 0
>>>
>>> with open(FILE_PATH, 'r') as f:
... print(f.read())
...
{"how_dare_you": "how_dare_you"}
>>>
```
So I cannot replicate your reported bug. There is no sign of any garbage characters inserted at the start of the file as you state.
----------
nosy: +steven.daprano
_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue42733>
_______________________________________
More information about the Python-bugs-list
mailing list