Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
is 'self' optional ?
#4
thanks I see now it was obvious I needed to call the class method to test whether the code worked without self.

2 things remainth :
a.) My point that when a function is called, self is not put in the parameter list, but it does appear in the function definition. This is dumb, and will take some getting used to.

e.g.
def deposit(self,amount) # 2 parameters when defined
but then when called...
my_account.deposit(10) # 1 parameter when called
b.) Still don't get why self is needed. Seems its a pretty deep routed reason to do with 'decorators', which is a concept i don't know of and have never used. If anyone knows of the simplest example of code or pseudo code that a complier would not be able to understand due to lack of 'self' I'd be interested to see it.

The wiki entry on 'this' says that lexical scoping can be used to fix problems that arise in with not having 'this'.
Lexical scoping is something I understand and use. However I don't see how it solves the problem of not having a 'this' because I don't see there's a problem to start with :/
https://en.wikipedia.org/wiki/This_(comp...ogramming)

Let me put it yet another way :

To my mind, 'self' is implicitly called in the variable name

my_account.deposit(10) # 'my_account' is 'self' !
that 'self' doesn't need to be in the parameters is a symptom of self being redundant, but seems the python dev team don't want to accept this !
Reply


Messages In This Thread
is 'self' optional ? - by meems - Nov-25-2016, 08:33 PM
RE: is 'self' optional ? - by metulburr - Nov-25-2016, 09:36 PM
RE: is 'self' optional ? - by Ofnuts - Nov-25-2016, 09:39 PM
RE: is 'self' optional ? - by meems - Nov-26-2016, 12:45 AM
RE: is 'self' optional ? - by metulburr - Nov-26-2016, 02:13 AM
RE: is 'self' optional ? - by nilamo - Dec-06-2016, 08:11 PM
RE: is 'self' optional ? - by metulburr - Dec-06-2016, 08:53 PM
RE: is 'self' optional ? - by nilamo - Dec-06-2016, 10:26 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  using mutable in function defintion as optional paramter akbarza 8 528 Apr-27-2024, 09:59 PM
Last Post: snippsat
  Trouble making an argument optional linuxnoob 2 2,954 Aug-31-2018, 01:52 AM
Last Post: linuxnoob

Forum Jump:

User Panel Messages

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