# Write
with open("data.txt", "w") as f:
f.write("Hello, file!")
# Read all
with open("data.txt") as f:
content = f.read()
# Read lines
with open("data.txt") as f:
for line in f:
print(line.strip())
# JSON
import json
with open("data.json", "w") as f:
json.dump({"key": "value"}, f)