[Python-Dev] reducing self.x=x; self.y=y; self.z=z boilerplate code (original) (raw)

Jp Calderone exarkun at divmod.com
Sat Jul 2 01:28:31 CEST 2005


On Fri, 01 Jul 2005 19:22:20 -0400, "Phillip J. Eby" <pje at telecommunity.com> wrote:

At 03:59 PM 7/1/2005 -0700, Ralf W. Grosse-Kunstleve wrote: [snip]

This extends to any number of arguments: class grouping: def init(self, x, y, z): self.dict.update(locals()) del self.self

If you use vars(self).update(locals()), it even looks halfway pleasant ;) I'm not sure what python-dev's current opinion of vars(obj) is though (I'm hoping someone'll tell me).

Of course, both of these fall over for slots'ful classes. It'd be nice if there were a general way to deal with attributes of an instance, regardless of the implementation details of its memory layout.

Jp



More information about the Python-Dev mailing list