Aaron Brady wrote: > On Dec 5, 8:21 pm, "Daniel Fetchinson" <[EMAIL PROTECTED]> > wrote: >> Hi folks, >> >> The story of the explicit self in method definitions has been >> discussed to death and we all know it will stay. However, Guido >> himself acknowledged that an alternative syntax makes perfect sense >> and having both (old and new) in a future version of python is a >> possibility since it maintains backward compatibility. The alternative >> syntax will be syntactic sugar for the old one. This blog post of his >> is what I'm talking about: >> >> http://neopythonic.blogspot.com/2008/10/why-explicit-self-has-to-stay... >> >> The proposal is to allow this: >> >> class C: >> def self.method( arg ): >> self.value = arg >> return self.value >> >> instead of this: >> >> class C: >> def method( self, arg ): >> self.value = arg >> return self.value >> >> I.e. explicit self stays only the syntax is slightly different and may >> seem attractive to some. > ... > > Would it be valid outside class definitions too? (As follows...) > > def sequence.shuffle( ): > x= sequence[ 0 ] > sequence[ 0 ]= sequence[ -1 ] > ...etc. > > shuffle( listA )
This is not what was intended. The discussion was explicitly only about class methods. What you are describing is weird and not generalizable. What if your method takes more than one parameter? You might argue that "sequence" would be the first argument in the list, like def sequence.shuffle(a, b): """ a, b: dummy arguments, just for the sake of the example """ x = sequence[0] sequence[0] = sequence[-1 ...etc. shuffle(listA, 1, 1) I can't think of any good reason to do this. What's more, the whole discussion was partly due to error messages like Traceback (most recent call last): File "classes.py", line 9, in obj.m2(1) TypeError: m2() takes exactly 3 arguments (2 given) Your proposition (well actually it is only a question) would result in error messages exactly like this one when one would not carefully read the method signature for example. > > Can you still call it by class membership? (As follows...) > > C.method( inst, arg ) That should not change at all, as the alternative syntax would actually be only syntactic sugar. -- http://mail.python.org/mailman/listinfo/python-list