Skip to content
Advertisement

AttributeError: ‘AnimalShelter’ object has no attribute ‘database’

I am not understanding why I am receiving this error as my .py file indicates that database is in fact an attribute. I have made sure that everything is indented as it should be and made sure that the correct .py is notated when importing AnimalShelter. I am following a walkthrough for this for class and the .ipynb definitely details everything as is it is in the walkthrough so there has to be something wrong with the .py file. I just dont understand what…

JavaScript
JavaScript
JavaScript
JavaScript

Advertisement

Answer

You need to change _init_ to __init__:

Change

JavaScript

to

JavaScript

When you call AnimalShelter(...), Python tries to call __init__ if it exists, and if it doesn’t, it uses a default implementation. It doesn’t automatically call _init_.

Therefore, self.database = self.client['project'] is never executed, so AnimalShelter doesn’t have a database attribute, which is the cause of your error.

User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement