py3k feature proposal: field auto-assignment in constructors

André andre.roberge at gmail.com
Sun Jan 27 22:18:29 EST 2008


On Jan 27, 10:57 pm, Paul Rubin <http://phr...@NOSPAM.invalid> wrote:
> Wildemar Wildenburger <lasses_w... at klapptsowieso.net> writes:
> > class Server(object):
> >      def __init__(self, self.host, self.port,
> >                   self.protocol, self.bufsize, self.timeout):
> >          pass
> > ?
>
> That could temporarily bind those attributes but it shouldn't
> persistently mutate the object.
>
> How about:
>
>     class Server(object):
>          def __init__(self, host, port, protocol, bufsize, timeout):
>             self.(host, port, protocol, bufsize, timeout) = \
>                   host, port, protocol, bufsize, timeout
>
> That's fairly explicit yet cuts down the total amount of boilerplate.

Not much; you're still repeating each variable name 3 times.  I prefer
the standard way of one definition per line over this notation
myself.

André



More information about the Python-list mailing list