why is "self" used in OO-Python?
Fredrik Lundh
fredrik at pythonware.com
Tue Jul 15 07:10:15 EDT 2008
ssecorp wrote:
> def append(self, item):
> self.stack.append(item)
>
> I can get to see the stack with var.stack but then why even implement
> append when I could do self.stack.append(x) etc.
> That way you could do away with OO completely.
Umm. Even if you were to write that, self and stack would still be
objects, and the "append" would still be a method defined by the stack
object, right?
What you seem to be referring to is the Law of Demeter, which is a
design guideline for avoiding unnecessary coupling, not an absolute
requirement for object-orientation:
http://en.wikipedia.org/wiki/Law_of_Demeter
As for the rest, I suspect you will have more success in using Python if
you use it to write Python programs, not Java programs:
http://dirtsimple.org/2004/12/python-is-not-java.html
</F>
More information about the Python-list
mailing list