Diez B. Roggisch wrote: > Just for the fun of it, I implemented a decorator: > > from functools import * > from inspect import * > > def autoassign(_init_): > @wraps(_init_) > def _autoassign(self, *args, **kwargs): > argnames, _, _, _ = getargspec(_init_) > for name, value in zip(argnames[1:], args): > setattr(self, name, value) > _init_(self, *args, **kwargs) > > return _autoassign >
This is neat. :) Could that maybe be extended to only assign selected args to the instance and let others pass unchanged. So that, for instance: @autoassign("foo", "bar") def __init__(self, foo, bar, baz): super(baz) ?W -- http://mail.python.org/mailman/listinfo/python-list