Idea about method parameters
Markus Schaber
markus at schabi.de
Mon Sep 24 12:57:57 EDT 2001
Hi,
in my Code, I very often have constructs like
class A:
def m(self, value):
self.value = value
# some other work to be done
This is annoying especially when having lots of parameters, which often
happens in __init__ methods.
Now I'd love to have the possibility to shorten this by typing:
class A:
def m(self, self.value):
pass # or the other work to be done
This should do exactly the same as:
class A:
def m(self, value):
self.value = value
del value
#the other work here
This could save some lots of typing, and even make some methods much
more readable in my eyes.
I would consider it a rather pythonic construct - straightforward and
clear.
The syntax to specify self.value inside the def statement is currently
invalid (at least using Python 1.5.2 and 2.0.1), and so I don't expect
it would break any existing code.
Maybe it is also sensible to allow A.value to assign to class variables
(maybe even superclasses make sense here).
What do you think about it? Is it worth the effort to think more about
it, and go the heavy way towards a PEP?
markus
--
"The strength of the Constitution lies entirely in the determination of
each citizen to defend it. Only if every single citizen feels duty
bound to do his share in this defense are the constitutional rights
secure." -- Albert Einstein
More information about the Python-list
mailing list