Idea about method parameters
Toby Dickenson
tdickenson at devmail.geminidataloggers.co.uk
Wed Sep 26 05:56:20 EDT 2001
Markus Schaber <markus at schabi.de> wrote:
>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
I assume you would not want to allow:
class A:
def __init__(self, some_other_object.value):
pass
But the distinction between the two is unexpected.
There is a way to shorten a __init__ with many parameters within the
current language, without sacrificing readability. Shorter, but also
wider.....
class A:
def __init__(self, value1, value2, value3):
self.value1,self.value2,self.value3 = value1,value2,value3
(my appologies if you already knew of this)
Toby Dickenson
tdickenson at geminidataloggers.com
More information about the Python-list
mailing list