Guido's new method definition idea
Bruno Desthuilliers
bdesth.quelquechose at free.quelquepart.fr
Sun Dec 7 13:18:49 EST 2008
News123 a écrit :
> Lie wrote:
>> On Dec 7, 1:02 am, News123 <news... at free.fr> wrote:
>>> What would be interesting would be some syntactical sugar to get rid of
>>> the 'self' (at least in the code body).
This has been debated to hell and back. And it's *not* going to happen.
>>> example:
>>> class C:
>>> class_elements a,b,c,d
>>>
>>> def method(self,arg):
>>> global d
>>> a,b,c = arg[0..3]
>>> d = a + b
>>> self.e = a + d
>>>
>> Nah, that would make it not explicit. Explicit here also means that to
>> refer to self's a, we need to explicitly refer to self.
>
> Well being explicit when trying to suggest an implicit syntax (in order
> to reduce typing) is a little difficult ;-)
>
> Though you're right my main goal is not being implicit but would be
> reducing typing and have shorter source code lines.
then use 's' instead of 'self'.
> If 'global '<varname>' is accepted inside a def, then moving
> 'class_elements <varnames>' inside the def could be acceptable as well
self.x is an instance attribute, not a class attribute. Aslo, the def
statement creates a function, not a method, so the notion of
"class_element" or however you name it is totally irrelevant here.
More information about the Python-list
mailing list