You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The code provided here doesnt seem to be able to lend books that are originally in the text database, only the ones that the user have added later. Any suggestions?
The code provided here doesnt seem to be able to lend books that are originally in the text database, only the ones that the user have added later. Any suggestions?
Because while reading and adding books to the list it is taking '\n' also at last of the book name, while for those books which are added later don't have the extra '\n' character at last.
The bookList formed by reading the text file is like: ['Python Crash Course\n', 'Head First Python\n', 'Learn Python3 - The Hard Way\n', 'Think Python\n', 'Automate The Boring Stuff using Python']
The solution is to use .strip() , while adding the books to the list to remove any white spaces(including '\n') from the book name so the corrected code for adding books into the list from the database is :
for book in bookDatabase:
booksList.append(book.strip())
bookDatabase.close() must be used after open..
The text was updated successfully, but these errors were encountered: