1
0
mirror of https://github.com/adambard/learnxinyminutes-docs.git synced 2025-08-12 17:54:26 +02:00

Add missing json import

This commit is contained in:
Marcel Ribeiro Dantas
2022-12-01 19:29:50 -03:00
committed by GitHub
parent 7b623a7998
commit 4d6309b2bd

View File

@@ -503,6 +503,7 @@ contents = {"aa": 12, "bb": 21}
with open("myfile1.txt", "w+") as file:
file.write(str(contents)) # writes a string to a file
import json
with open("myfile2.txt", "w+") as file:
file.write(json.dumps(contents)) # writes an object to a file