Forum

Author Topic: When do we need (self) in methods??  (Read 1926 times)

mikewilliams

  • Newbie
  • *
  • Posts: 1
    • View Profile
When do we need (self) in methods??
« on: January 30, 2019, 11:46:48 AM »
So I thought every python function definition needed (self) unless multiple paramters are being specified...what's the rule regarding self??

My __init__(): function does NOT have self, and when I instantiate with Shet() it says takes 0 positional arguments but 1 given. I tried adding a self to the definition, then it says missing 'self'... I can't possibly add anything to Shet() because what would I add-it's not expecting any arguments. what am I to do?? So confused.

Alexey Pasumansky

  • Agisoft Technical Support
  • Hero Member
  • *****
  • Posts: 14813
    • View Profile
Re: When do we need (self) in methods??
« Reply #1 on: January 30, 2019, 12:25:06 PM »
Hello mikewilliams,

Probably, the following article answers your question:
https://stackoverflow.com/a/2709832/2107734
Best regards,
Alexey Pasumansky,
Agisoft LLC

Lumuss

  • Newbie
  • *
  • Posts: 7
  • Lumus is light
    • View Profile
Re: When do we need (self) in methods??
« Reply #2 on: April 21, 2021, 11:14:29 AM »
Self was one of the things for me that took some time to sink in. As an analogy to understand it better I borrowed this instead of self from Java/JS.
this.name = name instead of self.name = name
where this is presupposed to be a reference to this object in question.

essaydune
BR,
Lumuss