Python Forum

Full Version: How to deal with self and __init__ in function
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
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
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-C...nheritance
https://python-forum.io/Thread-Classes-C...verloading

Any other good tutorial on OOP will do