Karol Zlot
Karol Zlot

Reputation: 4035

Call parent class function

It is first time I try to use super(), I tried many little changes to this code, but with all I got error on line where super() is.

I saw similar questions on SO, but they are not working in my case or I do something wrong

Could you help me to call getMessagesBodies() from list() ?

class Gmail:
    def getMessagesBodies(self, text):
        return self.unpackPayload(text)

    def unpackPayload(self, text):
        return (text)


    class getMessages:

        def __init__(self):
            self.service = auth()

        def list(self,text):
            return super(self).getMessagesBodies(text)  # error here, how to call getMessagesBodies properly?

Upvotes: 0

Views: 98

Answers (1)

Karl
Karl

Reputation: 1714

The problem is that you never specified what the parent class was for the getMessages class.

You should define the class like so:

class getMessages(Gmail):

Unless your child class is overriding the getMessagesBodies() function, you actually do not have to use super() to specify that you want to call the parent function. By using self.getMessagesBodies() in your child class it will automatically call the parent's function since the child inherits all the same functions from the parent.

So you can call the function without using super like:

self.getMessagesBodies(text)

Also, just a tip is that getMessages seems more like a function name then a class. Usually classes are fully capitalized and are an object, not an action.

Upvotes: 1

Related Questions