Dean Christian Armada Dean Christian Armada - 1 year ago 112
Python Question

self parameter error celery

I saw some blogs online where they put self parameters on their celery functions, why is mine causing an error like:

TypeError: xml_gr() takes exactly 1 argument (0 given)

Here is my code:

def xml_gr(self):
ftp = FTP('xxxxx')
ftp.login(user='xxxxx', passwd='xxxxx')
x = xml_operation('AGIN', GR_GLOBAL_CURRENT_DATE, ftp, "GR")

Answer Source

"self" is used within class member functions. When you call a member function in an instance of the class, the language automatically passes in the class instance as "self". "self" lets you access the members of the class.

class Thing:
    var1 = None
    def set_member(self, value):
        self.var1 = value

    def show_member(self, value):
        return self.var1

Then usage would be

a = Thing()

And you'd see the response 23. You don't have to pass in the "self" variable explicitly.

When you declare functions outside of a class, there is no reason to use "self".

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download