Rather than decorators, how about sections?
pm_mon at yahoo.com
Wed Aug 11 22:27:21 CEST 2004
Christopher T King wrote:
> On Wed, 11 Aug 2004, Paul Morrow wrote:
>>Fine, instead of Foo (the name of the class), use the word klass. It's
>>a popular name for the first parameter of a class method.
> My code uses 'cls' for this purpose. I'm sure others stick with 'self'.
> No matter what you pick, it will break something.
> To quote the Zen of Python: "Explicit is better than implicit."
Using 'self' to hold a class object or 'klass' (or 'cls') to hold an
instance object can make for some suprising code...
def foo(self): print "I'm a class method!"
def baz(cls): print "I'm an instance method!"
I imagine that the majority of us use 'self' in instance methods. There
can't be more than a few argument names that are commonly used to hold
class objects (klass, cls, ...) so maybe the compiler allows any one of
the popular spellings in that position.
If explicit truly was better than implicit, we wouldn't embrace dynamic
typing as we do. We would declare everything. And this language
wouldn't be any fun...
More information about the Python-list