JSON and CSV
The json module converts dicts to text and back. csv reads and writes rows. Both are in the standard library.
Example
import json, csv, io
d = {"a": [1, 2]}
s = json.dumps(d)
print(s, json.loads(s))
out = io.StringIO()
w = csv.writer(out); w.writerow(["x", "y"]); w.writerow([1, 2])
print(out.getvalue().strip())Result
{"a": [1, 2]} {'a': [1, 2]}
x,y
1,2Exercise
Text to object.
json.(s)
Quiz Test
These free lessons are for learning. Join a full course for projects, mentor feedback and a verified certificate.