py3k feature proposal: field auto-assignment in constructors

Paul Rubin http
Mon Jan 28 03:57:53 CET 2008

Wildemar Wildenburger <lasses_weil at> writes:
> class Server(object):
>      def __init__(self,, 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.

More information about the Python-list mailing list