Skip to content

Commit 42c65bd

Browse files
committed
Responded to Geir's latest comments and suggestions
1 parent 28ae377 commit 42c65bd

File tree

4 files changed

+7
-8
lines changed

4 files changed

+7
-8
lines changed

python-sqlite-sqlalchemy/project/data/author_book_publisher.csv

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
first_name,last_name,title,publisher
2-
Issac,Asimov,Foundation,Random House
2+
Isaac,Asimov,Foundation,Random House
33
Pearl,Buck,The Good Earth,Random House
44
Pearl,Buck,The Good Earth,Simon & Schuster
55
Tom,Clancy,The Hunt For Red October,Berkley
0 Bytes
Binary file not shown.

python-sqlite-sqlalchemy/project/examples/example_1/main.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,6 @@ def output_author_hierarchy(data):
8282
authors = data.assign(
8383
name=data.first_name.str.cat(data.last_name, sep=" ")
8484
)
85-
8685
authors_tree = Tree()
8786
authors_tree.create_node("Authors", "authors")
8887
for author, books in authors.groupby("name"):

python-sqlite-sqlalchemy/project/examples/example_2/main.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -65,17 +65,17 @@ def get_authors_by_publishers(session, ascending=True):
6565

6666

6767
def get_authors(session):
68-
"""Get a list of author objects"""
68+
"""Get a list of author objects sorted by last name"""
6969
return session.query(Author).order_by(Author.last_name).all()
7070

7171

7272
def add_new_book(session, author_name, book_title, publisher_name):
7373
"""Adds a new book to the system"""
7474

7575
# Get the author's first and last names
76-
first_name, last_name = author_name.split(" ")
76+
first_name, _, last_name = author_name.partition(" ")
7777

78-
# Get the book if it exists
78+
# Check if the book exists
7979
book = (
8080
session.query(Book)
8181
.join(Author)
@@ -92,7 +92,7 @@ def add_new_book(session, author_name, book_title, publisher_name):
9292
if book is not None:
9393
return
9494

95-
# get the book by the author
95+
# Check if the book exists for the author
9696
book = (
9797
session.query(Book)
9898
.join(Author)
@@ -156,8 +156,8 @@ def output_author_hierarchy(authors):
156156
for author in authors:
157157
author_id = f"{author.first_name} {author.last_name}"
158158
authors_tree.create_node(author_id, author_id, parent="authors")
159-
for index, book in enumerate(author.books):
160-
book_id = f"{author_id}:{book.title}:{index}"
159+
for book in author.books:
160+
book_id = f"{author_id}:{book.title}"
161161
authors_tree.create_node(book.title, book_id, parent=author_id)
162162
for publisher in book.publishers:
163163
authors_tree.create_node(publisher.name, parent=book_id)

0 commit comments

Comments
 (0)