Passing yourself as an argument in a helper method

I am working with a class and trying to call a helper method from a class. I got the following code to work, but I'm not sure why I need to pass the “I” as an argument to the helper function when I call it, when I already have the “I” as the argument in the method. Is there a reason why I should pass this as an argument when I call Frequency .__ helper (self, record) in the example below?

Thank!

class Frequency:

    def __init__(self, record):
        self.record = record

    def __helper(self, datalist)
        do something to datalist...

    def getFreq(self):
        allrec = self.record
        record = allrec[1].split(' ')
        var = Frequency.__helper(self, record)
        return var
+5
source share
2 answers

The right way to call a method is simply

var = self.__helper(record)

It does the same, but more intuitively.

+2
source

, , @staticmethod. , .

- :

class Frequency:
    @staticmethod
    def test(datalist):
        pass

.

+2

All Articles