Skip to content

Commit b6f4d2d

Browse files
committed
Made the filename an attribute of the address book object, so it is DRY, also so that the caller can get the filename
1 parent c86c76a commit b6f4d2d

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

week-09/code/address_book/address_book_data.py

+7-2
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,16 @@ class AddressBook(object):
1313
"""
1414
def __init__(self):
1515
self.book = []
16+
self.filename = "a_book.json"
1617

17-
def save_to_file(self, filename='a_book.json'):
18+
def save_to_file(self, filename=None):
19+
if filename != None :
20+
self.filename = filename
1821
json.dump(self.book, open(filename, 'wb'), indent=4 )
1922

20-
def load_from_file(self, filename='a_book.json'):
23+
def load_from_file(self, filename=None):
24+
if filename != None :
25+
self.filename = filename
2126
self.book = json.load( open(filename, 'rb') )
2227

2328

0 commit comments

Comments
 (0)