assigning values in __init__

Steve Holden steve at
Thu Nov 9 14:36:17 CET 2006

Steven D'Aprano wrote:
> On Thu, 09 Nov 2006 12:27:12 +1100, Ben Finney wrote:
>> John Salerno <johnjsal at> 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))
Except, of course, that you *can't* do that: I think you meant to use 
equals signs instead of colons?

> 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.
Steve Holden       +44 150 684 7255  +1 800 494 3119
Holden Web LLC/Ltd
Skype: holdenweb
Recent Ramblings

More information about the Python-list mailing list