<div dir="ltr">On Wed, Jul 30, 2008 at 2:46 PM, Matthew Fitzgibbons <span dir="ltr"><<a href="mailto:elessar@nienna.org">elessar@nienna.org</a>></span> wrote:<br><div class="gmail_quote"><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
Robert Dailey wrote:<br>
<blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;"><div><div></div><div class="Wj3C7c">
On Wed, Jul 30, 2008 at 1:03 PM, Brett g Porter <<a href="mailto:bgporter@acm.org" target="_blank">bgporter@acm.org</a> <mailto:<a href="mailto:bgporter@acm.org" target="_blank">bgporter@acm.org</a>>> wrote:<br>
<br>
Robert Dailey wrote:<br>
<br>
This is an example of a response I'm looking for:<br>
"The self parameter is required because the parser is a bit old<br>
and needs to know the exact object you're referencing"<br>
<br>
This is _not_ an example of what I'm looking for:<br>
"Specifying self is a great mysterious thing that we should<br>
never question. Do not question the language! The language is<br>
mighty! Don't bring C++ to Python!"<br>
<br>
<br>
Fredrik Lundh has written a very clear explanation of this at<br>
<a href="http://effbot.org/pyfaq/why-must-self-be-used-explicitly-in-method-definitions-and-calls.htm" target="_blank">http://effbot.org/pyfaq/why-must-self-be-used-explicitly-in-method-definitions-and-calls.htm</a><br>
<br>
(or <a href="http://bit.ly/3EUiCf" target="_blank">http://bit.ly/3EUiCf</a> if you don't feel like stitching that URL<br>
back together...)<br>
<br>
<br>
This sounds like an article of opinion. He's not really given any reasons other than "Well, it makes this easier or look better". True that declarations are the determining factor in C/C++, however I was thinking of more or less an implied 'self'. For example:<br>
<br>
# Consider this normal syntax:<br>
class MyFoo:<br>
def DoFoo( self ):<br>
self._member = 6<br>
<br>
# Elimintating 'self' in the parameter list should still work as far as the<br>
# interpreter is concerned, since 'self' in this case now acts like 'this'<br>
# in C++. The below code should be equivalent.<br>
class MyFoo:<br>
def DoFoo():<br>
self._member = 6<br>
<br>
Given the code samples above, is there any technical reason why this cannot be done? Thanks for the input guys, and thanks more over for keeping this easy-going.<br>
<br>
<br></div></div>
------------------------------------------------------------------------<div class="Ih2E3d"><br>
<br>
--<br>
<a href="http://mail.python.org/mailman/listinfo/python-list" target="_blank">http://mail.python.org/mailman/listinfo/python-list</a><br>
</div></blockquote>
<br>
Your first example could be written:<br>
<br>
class MyFoo(object):<br>
def do_foo(the_foo_instance):<br>
the_foo_instance._member = 6<br>
<br>
'self' is not special the way 'this' is in C++. It's just a name for an object reference just like any other name for any other object reference.<br>
<br>
-Matt<br>
</blockquote></div><br>Yes, I realize that it can have any name. But this does not change its purpose. It was simply an example. In the second code snippet I gave you, 'self' would become a reserved word and a user would have to use that to reference the object from which the function was called.<br>
</div>