CSV files
import csv
rows = [
["Tom", 25],
["Anna", 30]
]
with open("people.csv", "w", newline="") as file:
writer = csv.writer(file)
writer.writerow(["Name", "Age"])
writer.writerows(rows)
with open("people.csv", "r") as file:
reader = csv.reader(file)
for row in reader:
print(row)
JSON files
import json
person = {"name": "Tom", "age": 25}
jsonString = json.dumps(person)
print(jsonString)
data = json.loads('{"name": "Tom", "age": 25}')
print(data["name"])
numbers = json.loads('[1, 2, 3, 4]')
print(numbers)
with open("data.json", "w") as file:
json.dump(person, file)
with open("data.json", "r") as file:
data = json.load(file)
print(data)