forked from CodeMouse92/DeadSimplePython
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path__main__.py
More file actions
30 lines (21 loc) · 824 Bytes
/
__main__.py
File metadata and controls
30 lines (21 loc) · 824 Bytes
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
from .bookshelf import Bookshelf
from .book import Book
def write_demo_file():
# Write to file
cheuk_ting_bookshelf = Bookshelf(
Book("Automate the Boring Stuff with Python", "Al Sweigart", 592, 592),
Book("Doing Math with Python", "Amit Saha", 264, 100),
Book("Black Hat Python", "Justin Seitz", 192, 0),
Book("Serious Python", "Julien Danjou", 240, 200),
Book("Real-World Python", "Lee Vaughan", 370, 370),
)
with open('mybookshelf.shlf', 'bw') as file:
cheuk_ting_bookshelf.write_to_stream(file)
def read_demo_file():
with open('mybookshelf.shlf', 'br') as file:
lais_bookshelf = Bookshelf.from_stream(file)
for book in lais_bookshelf:
print(book.title)
if __name__ == "__main__":
write_demo_file()
read_demo_file()