A better self

David LeBlanc whisper at oz.net
Tue Jul 9 19:42:58 EDT 2002


Except, of course, "self" is not the name of the first argument, it's merely
the identifier most often used for the first argument.

This is essentially the same as the posted example:
class foo:
    def __init__(this, me, me2, me3):
        this.a = me
        this.b = me2
        this.c = me3

    def bar(this):
        print this.a, this.b, this.c

b = foo("ba", "bb", "bc")

b.bar()

I have no problem with "self" (or whatever) being equivelent to a leading
'.', but '..' would be confused with "up directory" syntax of U*x - although
it's tempting to suggest it as an alternative for global <grin>.

I'm not sure what you meant by ".attribute should have an extra space...".

David LeBlanc
Seattle, WA USA

> -----Original Message-----
> From: python-list-admin at python.org
> [mailto:python-list-admin at python.org]On Behalf Of Erik Max Francis
> Sent: Tuesday, July 09, 2002 16:17
> To: python-list at python.org
> Subject: Re: A better self
>
>
> David LeBlanc wrote:
>
> > I notice that in every discussion of self, there's always a '.' in
> > there.
> > So, why not make a leading '.' mean self? AFAIK, it's otherwise
> > currently
> > illegal. The only drawback that I can think of is that it's less
> > visible as
> > a first argument for class defs.
> >
> > class foo():
> >         def __init__(., me, me2, me3)
> >                 .a = me
> >                 .b = me2
> >                 .c = me3
> >         def fee(.)
> >                 print .a, .b, .c
> >         def bar(.)
> >                 .fee()
>
> This doesn't totally revolt me, but I would prefer that the "self"
> argument still be an explicit self:
>
> 	def __init__(self, me, me2, me3) ...
>
> so that the notation `.attribute' is just a shortcut for
> `self.attribute'.  Having the "self" argument written as . suggests that
> accessing an attribute in it should involve an extra space, e.g.
> `..attribute' which is clearly not what you meant.
>
> `self' as the name of that first argument is already so entrenched it's
> really hard to come up with reasonable arguments about replacing it.
>
> --
>  Erik Max Francis / max at alcyone.com / http://www.alcyone.com/max/
>  __ San Jose, CA, US / 37 20 N 121 53 W / ICQ16063900 / &tSftDotIotE
> /  \ See the son in your bad day / Smell the flowers in the valley
> \__/ Chante Moore
>     Bosskey.net: Aliens vs. Predator 2 / http://www.bosskey.net/avp2/
>  A personal guide to Aliens vs. Predator 2.
> --
> http://mail.python.org/mailman/listinfo/python-list






More information about the Python-list mailing list