-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnouns.py
33 lines (24 loc) · 812 Bytes
/
nouns.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
import json
def create_noun(thing_name, thing_desc):
things_dict = {
thing_name : thing_desc
}
# Serializing json
json_object = json.dumps(things_dict, indent=4)
# Writing to sample.json
with open("nouns.json", "w") as outfile:
outfile.write(json_object)
def add_noun(thing_name, thing_desc):
filepath = 'nouns.json'
with open(filepath, 'r') as fp:
information = json.load(fp)
information.update({thing_name:thing_desc})
with open(filepath, 'w') as fp:
json.dump(information, fp, indent=4)
def remove_noun(thing_name):
filepath = 'nouns.json'
with open(filepath, 'r') as fp:
information = json.load(fp)
information.pop(thing_name)
with open(filepath, 'w') as fp:
json.dump(information, fp, indent=4)