another syntax we don't need (initializers)

Andrew Koenig ark at research.att.com
Mon Dec 9 16:34:19 EST 2002


Jeff> We could add syntax to Python to support something like this:
Jeff>     class Foo:
Jeff>         def __init__(self, self.x): pass

Is this really an advantage over

          class Foo:
              def __init__(self, x): self.x = x

? The latter version is only one character longer!  Moreover, it
allows for the possibility that the attribute name might differ from
the formal parameter name.

Moreover, the reason for the C++ syntax is that in C++, initialization
is fundamentally different from assignment.  There is no such
difference in Python, so there is no need for special syntax to cater
to that difference.

-- 
Andrew Koenig, ark at research.att.com, http://www.research.att.com/info/ark



More information about the Python-list mailing list