Ben Wilson <[EMAIL PROTECTED]> wrote: >I would like to dynamically assign object attributes: > >dict = { > a : 1, > b : 2, >} > >for key,val in dict : > obj.key = val > >I've googled to no effect, or maybe I'm needing to be hit with the >appropriately sized clue-by-four.
The conventional clue-by-four applied to this question is "Don't do that: just put the dictionary (or a copy of it) in the object with obj.d = d (and don't shadow the built-in dict while you're at it)." Having spent significant portions of the last two days coping with the mess of adding functionality to a class written by someone who thought doing what you want to do was a Good Idea, I can only concur with that conventional wisdom. Really. Don't do it. (Unless you have a damn good reason. In which case, you've already been pointed at setattr().) -- \S -- [EMAIL PROTECTED] -- http://www.chaos.org.uk/~sion/ ___ | "Frankly I have no feelings towards penguins one way or the other" \X/ | -- Arthur C. Clarke her nu becomeþ se bera eadward ofdun hlæddre heafdes bæce bump bump bump
-- http://mail.python.org/mailman/listinfo/python-list