-
Notifications
You must be signed in to change notification settings - Fork 16
/
Copy pathfiles.py
45 lines (36 loc) · 1008 Bytes
/
files.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# f = open('animals.csv')
# for line in f:
# print(line)
# f.close()
# with open('animals.csv', 'r') as f:
# print(f.read())
# import csv
# with open('animals.csv', 'r') as f:
# animals = csv.reader(f)
# for row in animals:
# if row[-1] == 'True':
# print("{0} is a {1} and is housebroken".format(row[0], row[1]))
# elif row[-1] == 'False':
# print("{0} is a {1} and is not housebroken!".format(row[0], row[1]))
# import json
# with open('animals.json', 'r') as r:
# data = json.load(r)
# for row in data:
# print(row['name'])
# f = open('cars.txt', 'a')
# cars = ['chevy', 'tesla', 'ford']
# for car in cars:
# f.write(car + '\n')
# f.close()
# with open('cars.txt', 'a') as f:
# cars = ['chevy', 'vw', 'mazda']
# for car in cars:
# f.write(car + '\n')
cars = [
{"make": "chevy"},
{"make": "tesla"},
{"make": "porsche"}
]
import json
with open('cars.json', 'w') as f:
json.dump(cars, f)