简体   繁体   中英

Python function definition not working

I've got a problem with a function which is defined in a Python class:

class DatabaseHandler:

    def get_messages_by_last_mid(self, uidReceiver, last_mid):

        self.cursor.execute("SELECT uidSender, content FROM messages WHERE MID > ?", str(last_mid))

        ret_value = []
        result = self.cursor.fetchone()
        while result != None:
            ret_value.append(result)
            result = self.cursor.fetchone()

        return ret_value

    def get_messages_by_last_group_id(self, uidReceiver, last_gid):

        self.cursor.execute("SELECT gidreceiver, uidsender, content FROM groupmessages WHERE mid > ?", str(last_gid))

        ret_value = []
        result = self.cursor.fetchone()
        while result != None:
           ret_value.append(result)
           result = self.cursor.fetchone()

        return ret_value

But only the function get_messages_by_last_mid() works, the other one produces the following error:

AttributeError: DatabaseHandler instance has no attribute 'get_messages_by_last_group_id'

Thanks in advance :)

Indentation can be a silent killer in Python if you're coming from various other programming languages. As you already know, indentation is how Python determines the scope of methods, functions, classes, loops, etc. as you write your code. Make sure your indentation is consistent! You can use the command-line option -t or -tt to python to check yourself.

Sorry guys, I had used an old package. My problem has been fixed. Thanks for your answers.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM