On 2006-11-09, Steven D'Aprano <[EMAIL PROTECTED]> wrote: > On Thu, 09 Nov 2006 12:27:12 +1100, Ben Finney wrote: > >> John Salerno <[EMAIL PROTECTED]> writes: >> >>> Ben Finney wrote: >>> > If you pass a *mapping* of the >>> > "I-might-want-to-add-more-in-the-future" values, then you get both >>> > explicit *and* expandable, without an arbitrary unneeded sequence. >>> >>> Do you mean by using the **kwargs parameter? >> >> No. > > Well, that'll teach me to put words in your mouth. > > [snip] >> If you have a group of named, semantically-related, unsequenced values, >> pass them into the function as a mapping object (a dict object). > > Still, if you are doing this: > > mapping_object = {"strength": roll_dice(10), > "intelligence":roll_dice(10), > "dexterity":roll_dice(10)} > my_character = Character(mapping_object) > > then there is little benefit to building the dict just for the purposes of > passing it to Character(), never to use it again, not when you can do this: > > my_character = Character(strength: roll_dice(10), > intelligence:roll_dice(10), dexterity:roll_dice(10))
But you will have to adapt this if you want extra or different characteristics. Personnally I would prefer something like: chardict = {} for char in characteristics: chardict[char] = roll_dice(10) my_character = Character(chardict) This way you only have to keep your characteristics in one place. > If you happen to already have collected your character attributes in a > mapping object for some other reason, then well and good, pass it into the > function. Otherwise, well, I believe the correct container for > character attributes is a Character, not a dict. What is wrong with keeping the character attributes in a dict in the Character? -- Antoon Pardon -- http://mail.python.org/mailman/listinfo/python-list