Closed vidyabhandary closed 4 years ago
Hello @vidyabhandary! Thanks for opening this PR. We checked the lines you've touched for PEP 8 issues, and found:
ch09/movieclassifier/app.py
:Line 34:57: E502 the backslash is redundant between brackets
Thanks for the PR. Just wondering where in the code you faced issues? Afaik running the code with review_db didn't cause any problems in my case.
I faced a problem when I ran python app.py
in movieclassifier, submitted the review and clicked 'Correct' / 'Incorrect'. I got a 'NameError: name 'review_db' is not defined'
. Changing the code to match the declaration of the database connection in app.py
worked (at all three places - In the PR only one change is present, one more should have been present). Puzzled it is working for you ! I realized I specifically had to change it to review_db
and not db
.
Since the code to change is different than what it should be (in case it is a problem) I will close this PR. Thanks for the GitHub repo. I am learning a lot going through the chapter jupyter notebooks.
I was just taking another look at the code, and it seems like "review_db" should be correct, e.g., https://github.com/rasbt/python-machine-learning-book-3rd-edition/blob/master/ch09/movieclassifier/app.py#L34
Was there some other place where it was defined as "db" instead of "review_db" -- sorry, I am currently not seeing it and want to make sure that I didn't overlook a potential issue here.
Line 18 and Line 73 - it is defined as db in the same app.py file.
Oh I see. But that's just a Python variable name.
Yes. However since review_db was not defined in that py file anywhere else, I got an error.
Hm, maybe you called the data base table inside review.sqlite db
instead of review_db
by accident? When I check the code for creating the review.sqlite file, it looks correct to me:
This is from https://github.com/rasbt/python-machine-learning-book-3rd-edition/blob/master/ch09/ch09.ipynb
which is also mentioned in the chapter.
Checked again - all are called 'review_db'.
conn = sqlite3.connect('reviews.sqlite')
c = conn.cursor()
c.execute('DROP TABLE IF EXISTS review_db')
c.execute('CREATE TABLE review_db (review TEXT, sentiment INTEGER, date TEXT)')
example1 = 'I love this movie'
c.execute('INSERT INTO review_db (review, sentiment, date) VALUES (?, ?, DATETIME("now"))', (example1, 1))
example2 = 'I dislike this movie'
c.execute('INSERT INTO review_db (review, sentiment, date) VALUES (?, ?, DATETIME("now"))', (example2, 0))
conn.commit()
conn.close()
ok that's great. Thanks
Changed review_db to db in the SQL INSERT statement