Self Nanny

Amit Patel amitp at Xenon.Stanford.EDU
Mon Mar 27 22:44:06 CEST 2000

 bjorn  <bjorn at> wrote:
| Paul Prescod wrote:
| > I have never seen correct Python code where the first argument to a
| > method was not named "self". Therefore I think that the flexibility of
| > allowing it to be named "spam" is more trouble than it is worth. Python
| > should just require "self" be named "self".
| Until we get proper lexical scoping, in which case an explicit self
| argument is not only needed, but needs to have the opportunity to be
| different from the enclosing method's self:
|     class Outer:
|         def foo(self):
|             self.x = 1
|             class Inner:
|                 def bar(me):
|                     me.x = 2
|                     return me.x + self.x
|             return Inner

With lexical scoping, we might want to say that all the methods are
"closed" under self:

  class Outer
    def class_methods_here(): pass

    def __constructor__(self, x, y):
      def foo():
        self.dist = sqrt(x*x+y*y)

Then if there are inner classes, we could use a different name for the
'self' object, but we still wouldn't need to have self in *each*
method.. we can define "self" at a new scope level all outside the
methods, but inside the inner class.

Sorry, I'm just dreaming.

       - Amit

More information about the Python-list mailing list