mirror of
https://github.com/adambard/learnxinyminutes-docs.git
synced 2025-08-13 18:24:39 +02:00
Add missing json import
This commit is contained in:
committed by
GitHub
parent
7b623a7998
commit
4d6309b2bd
@@ -503,6 +503,7 @@ contents = {"aa": 12, "bb": 21}
|
|||||||
with open("myfile1.txt", "w+") as file:
|
with open("myfile1.txt", "w+") as file:
|
||||||
file.write(str(contents)) # writes a string to a file
|
file.write(str(contents)) # writes a string to a file
|
||||||
|
|
||||||
|
import json
|
||||||
with open("myfile2.txt", "w+") as file:
|
with open("myfile2.txt", "w+") as file:
|
||||||
file.write(json.dumps(contents)) # writes an object to a file
|
file.write(json.dumps(contents)) # writes an object to a file
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user