dimanche 31 janvier 2021

Why is my els estatment giving me a syntax error Python

The else statement before the exception keeps giving me a syntax error I have tried deleting all the spaces and making sure I am using the same number of tabs to get the indentation, am I missing something simple

from pymongo import MongoClient from bson.objectid import ObjectId

class AnimalShelter(object): """crud operations for Animal collection in MongoDB"""

def __init__(self, username, password):
    # Initializing the MongoCLient. this helps to 
    #acess the MongoDB databse and collections.
    self.client = MongoCLient('mongodb://%s:%s@localhost:27017' % (username, password))
    self.database = self.client['project']
    
    # Create method to implement C in CRUD
    def create(self, data):
        if data is not None:
            if data:
                self.database.animals.insert(data) # data should be dictionary
                return True
            else:
                return False
        else:
            raise Exception("Nothing to save, because data parameter is empty")
            
    # Create method to implement R in CRUD
    def read(self, search):
        if search is not None: # if search is not None it will return all the rows that match
            if search:
                searchResults = self.database.animals.find(search)
                return searchResults
        else:
            execption = "Nothing to search, because search parameter is empty"
            return exception

Aucun commentaire:

Enregistrer un commentaire