should "self" be changed?
Marko Rauhamaa
marko at pacujo.net
Tue May 26 15:46:57 EDT 2015
zipher <dreamingforward at gmail.com>:
> Would it be prudent to rid the long-standing "argument" (pun
> unintended) about self and the ulterior spellings of it, by changing
> it into a symbol rather than a name?
>
> Something like:
>
> class MyClass(object):
>
> def __init__(@):
> @.dummy = None
>
> OR, even better, getting *rid of it* in the parameter list, so it
> stops confusing people about how many parameters a method needs, and
> transform it into a true *operator*.
Python's practice works. However, a small problem is presented by nested
classes:
class Connection:
def __init__(self):
class Idle:
def signal_start(self):
# how to refer to the outer self
:
:
Solutions include:
class Connection:
def __init__(self):
class Idle:
def signal_start(_):
self.set_state(Ready)
:
class Connection:
def __init__(self):
conn = self
class Idle:
def signal_start(self):
conn.set_state(Ready)
:
I have used the latter method recently.
Marko
More information about the Python-list
mailing list