What's the reason of passing a value for a self reference in class functions in python? For instance:
class MyClass:
"""A simple example class"""
i = 12345
def f(**self**):
return 'hello world'
By doing this, aren't you doing the compiler's work?
Many electrons have given their lives to discussing this question over the years.
Guido (python's creator) weighs forth on the issue in his blog here, in response to a proposal last year to get rid of the explicit self. The python FAQ also covers the issue.
Finally, if you don't mind a bit of grey magic, you can use a metaclass to get rid of it. Although there are good reasons why you shouldn't do that (it breaks properties, will make it harder for you to understand other people's code, and it will confuse any other python programmer who looks at your code).
Guido says: http://neopythonic.blogspot.com/2008/10/why-explicit-self-has-to-stay.html
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With