Python Forum
How to deal with self and __init__ in function
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How to deal with self and __init__ in function
#1
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
Reply
#2
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
If you can't explain it to a six year old, you don't understand it yourself, Albert Einstein
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs

Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  how to deal with problem of converting string to int usthbstar 1 1,931 Jan-05-2021, 01:33 PM
Last Post: perfringo
  __init__ function arguments CoderMan 4 2,980 Jan-27-2019, 02:04 PM
Last Post: stullis
  How Does pyspark deal with Spaces in Queries cpatte7372 3 2,888 Jul-31-2018, 09:53 PM
Last Post: micseydel
  How to deal with more than 1 input in a line mmaz67 1 2,318 Jul-18-2018, 12:27 PM
Last Post: ichabod801
  Geany frustration how to deal with tabs and spaces and CR mlytle0 2 4,396 Sep-14-2017, 11:51 AM
Last Post: metulburr
  Why is there an __init__ statement within the __init__ definition iFunKtion 7 5,962 Feb-06-2017, 07:31 PM
Last Post: Larz60+

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020