Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
211 views
in Technique[技术] by (71.8m points)

python - truncating file in 'r+' makes the entire file rectangles

The following is my code:

import json
id = "iderq23512345123521"
with open("file.json", "r+") as f:

        data = json.loads(f.read())
        f.truncate(0)
        del data[id]
        data = json.dumps(data)
        f.write(subs)

This is what the file looks like after I do it

When I try to copy and paste the characters, they don't show up


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Rename the id variable to something else (like id2), id already is a python func


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...