proposal, change self. to .

David C. Ullrich dullrich at sprynet.com
Tue Aug 5 11:58:42 EDT 2008


In article <VpudnQrs_eADNAjVnZ2dnUVZ_gSdnZ2d at earthlink.com>,
 Nick Dumas <drakonik at gmail.com> wrote:

> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA1
> 
> It's also worth noting that you can use a different name for the object
> that represents your class. If you did def __init__(foo):pass, then you
> would be able to access the class's objects with foo.objectname. Using
> self is simply the recommended standard.

Close, but not quite. "self" is not really the name of the
object, it's just the name of the first parameter. You
can change the name of that parameter any time you want.
If you do this:

class C(object):
  def __init__(this, data):
    this.data = data
  def __str__(me):
    return str(me.data)
  def double(random):
    random.data = random.data*2

c = C('Hello')
print c
c.double()
print c
c.data = 21
c.double()
print c

you see

Hello
HelloHello
42

(If 'self' were the name of the object there'd be no
reason it had to be included in the parameter list for
methods...)

> Heiko Wundram wrote:
> > Am 03.08.2008, 12:51 Uhr, schrieb Equand <equand at gmail.com>:
> >> how about changing the precious self. to .
> >> imagine
> >>
> >> self.update()
> >>
> >> .update()
> >>
> >> simple right?
> > 
> > What about:
> > 
> > class x:
> > 
> >      def x(self,ob):
> >          ob.doSomethingWith(self)
> > 
> > ? Not so simple anymore, isn't it? If you're not trolling, there's
> > hundreds of reasons why the explicit self is as it is, and it's not going
> > to go away, just as a thread that produced immense amounts of response
> > demonstrated around a week ago. Read that, and rethink.
> > 
> > --- Heiko.
> -----BEGIN PGP SIGNATURE-----
> Version: GnuPG v1.4.9 (MingW32)
> Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org
> 
> iEYEARECAAYFAkiVqEcACgkQLMI5fndAv9j8KgCgmS2e+bTOT+sUPLYhtHBOVlyq
> kxwAn028YSOGYGB4RyHZxYq6n4+tsSd+
> =vH9d
> -----END PGP SIGNATURE-----

-- 
David C. Ullrich



More information about the Python-list mailing list