Write file with python

Scrivere un semplice file di testo

with open("demofile.txt", "a") as f:
  f.write("Now the file has more content!")

Scrivere un json formattato

import json
 
data = {
    "some": "content"
}
 
with open('data.json', 'w', encoding='utf-8') as f:
    json.dump(data, f, ensure_ascii=False, indent=4)