Thanks to both of you, that will work. I can see the argument for assigning everything manually, but I have each parameter on its own line with a comment to explain what it does, and I know I want all parameters to be class-level for every instantiation, so saying "self.[varName]=[varName]" twenty times seems like a waste of time and space.
On 11/2/11, Christian Witts <cwi...@compuscan.co.za> wrote: > On 2011/11/02 03:15 PM, Alex Hall wrote: >> Hi all, >> I have a class which takes a large number of optional arguments for >> its __init__. Instead of going through every single one and assigning >> it to "self.[name]", is there some quick way to take all the >> parameters of the constructor and assign them all to self.[name] in >> one step? >> > class Test(object): > def __init__(self, param1, param2, param2, **kw): > self.__dict__.update(locals()) > self.__dict__.update(kw) > > I do prefer assignment by hand, just feels nicer especially when looking > at it in the future. > -- > > Christian Witts > Python Developer > > // > -- Have a great day, Alex (msg sent from GMail website) mehg...@gmail.com; http://www.facebook.com/mehgcap _______________________________________________ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor