Python Forum
How to deal with self and __init__ in function - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: General Coding Help (https://python-forum.io/forum-8.html)
+--- Thread: How to deal with self and __init__ in function (/thread-33458.html)



How to deal with self and __init__ in function - MrFloyd_telomerase - Apr-26-2021

I am sorry for naive questions, I am new to python.

I am trying to understand how to deal with self when I am trying to understand a function which was written by a third party.
for example:

def __init__(self, peak_finder = None, peak_fitter = None, properties = None, **kwds):
        """
        peak_finder - A PeakFinder object.
        peak_fitter - A PeakFitter object.
        properties - Which properties to return, e.g. "x", "y", etc.
        """
        super(PeakFinderFitter, self).__init__(**kwds)

        self.peak_finder = peak_finder
        self.peak_fitter = peak_fitter
        self.properties = properties

        # The properties must include at least 'x' and 'y'.
        assert ("x" in self.properties), "'x' is a required property."
        assert ("y" in self.properties), "'y' is a required property."
There is awhy to disable self, I guess I can delete all the self words but it seems not the correct way.

In addition,
For few time I have already sow people use __init__, what is the meaning of it, why using it?

Sorry for the naive questions Tongue


RE: How to deal with self and __init__ in function - buran - Apr-26-2021

It looks you are in need of a good OOP tutorial
You cans start with
https://python-forum.io/Thread-Classes-Class-Basics
then continue with
https://python-forum.io/Thread-Classes-Class-Intermediate-Inheritance
https://python-forum.io/Thread-Classes-Class-Intermediate-Operator-Overloading

Any other good tutorial on OOP will do