assigning values in __init__

Steven D'Aprano steve at REMOVE.THIS.cybersource.com.au
Wed Nov 8 17:33:11 EST 2006


On Wed, 08 Nov 2006 10:55:57 -0500, John Salerno wrote:

> Ben Finney wrote:
>> John Salerno <johnjsal at NOSPAMgmail.com> writes:
>> 
>>> But I do like Steve's suggestion that it's better to be explicit
>>> about each attribute, instead of just accepting a list of numbers
>>> (but I can't help but feel that for some reason this is better,
>>> because it's more general).
>> 
>> 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? 

Yes, that's what Ben is talking about. 

> If I do this, doesn't it 
> mean that *anything* could be added though? Misspelled words and 
> completely unrelated attributes as well?

**kwargs flexibility carries a risk. You may consider it worthwhile or not.


> Or does this matter as long as you are handling the processing yourself 
> internally and not allowing users access to the Character class?

Only you can decide whether **kwargs' convenience and flexibility
outweighs its risk.


-- 
Steven.




More information about the Python-list mailing list