Question: Can you fix the below code meant for Jupyter Notebook: Traceback ( most recent call last ) Input In [ 6 ] , in animal
Can you fix the below code meant for Jupyter Notebook: Traceback most recent call last
Input In in
animalshelter.py
from pymongo import MongoClient
from bson.objectid import ObjectId
class AnimalShelterobject:
CRUD operations for Animal collection in MongoDB"""
def initself username, password:
# Initializing the MongoClient
USER 'aacuser'
PASS 'Justice
HOST nvdesktopservices.apporto.com'
PORT
DB 'AAC'
COL 'animals'
# The below Code Initialized the Connection
self.client MongoClientmongodb:s:s@s:dUSERPASS,HOST,PORT
self.database self.clientsDB
self.collection self.databasesCOL
def createself data:
if data is not None:
self.database.animals.insertonedata
return True
else:
raise ExceptionNothing to save, because data parameter is empty"
return False
#Method to implement the R in CRUD:
def readallself data:
cursor self.database.animals.finddataid: False
return cursor
def readself data:
return self.database.animals.findonedata
PythonTestingScript.ipynb
from animalshelter import AnimalShelter
shelter AnimalShelteraacuser "Justice
# Test create method
data Age: years", "Type": "Dog"
if shelter.createdata:
printAnimal has been added."
else:
raise ExceptionError: Animal not added, please try again."
# Test read method
animals shelter.readType: "Dog"
printanimals
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
