Many Python programmers shorten "self" to just "s."
I feel that this is one of the only times that the Python language shows some ugliness. What is even stranger is that you can forget to put in the self parameter and it will compile without any problem. It's only when you try to use the member function that you get the somewhat cryptic error: "TypeError: myFunc() takes no arguments (1 given)"
And we (python supporters) should admit that this is one of the very rare places ( might be, the only place ) where the statement "Python is designed so that you only need to press the keys that absolutely must" is violated.
i am new to python but this seems ugly isn't there a way that doesnt force you to use a self reference in every method ?
I'm new to python this time.
at first I shocked by the very "self"!
It takes a just 2days to understand what it is,
how it works so I thinks it's just like a foot of snake.
I'm not a professional but just thinking!
This section of the book should address the issue of how to make multiple constructors with different arguments. I've been wrestling with this for almost two valuable hours!
It occurred to me that I can declare the constructor to take the maximum number of arguments, then I can check each argument to see if it equals None. But wow, can things really be that ugly? To me showing an example of how to do this would be a very important part of your introduction.
> However, when you call a method for an object as in x.show( ), you do not hand it the reference to the object – that is done for you
I might be picking nits here but I would say that you do - it's just before the dot instead of in the parenthesis..
I disagree with the fact that "__init__" is a constructor, it's an initializer. In the new-style class "__new__" is to some extend a constructor (it is not constrained to return an new instance of the class , although it''s the normally expected behaviour).
I think it should be explained that python choose this syntax because "explicit is better than implicit".
Both methods have “self” as their first argument. C++ and Java both have a hidden first argument in their class methods, which points to the object that the method was called for and can be accessed using the keyword this. Python methods also use a reference to the current object, but ---> as "explicit is better than implicit",I think it should be explained that python choose this syntax because "explicit is better than implicit".
Both methods have “self” as their first argument. C++ and Java both have a hidden first argument in their class methods, which points to the object that the method was called for and can be accessed using the keyword this. Python methods also use a reference to the current object, but ---> as "explicit is better than implicit",