Design: method in class or general function?

Steve D'Aprano steve+python at pearwood.info
Thu Sep 7 08:16:07 EDT 2017


On Thu, 7 Sep 2017 07:20 pm, Leam Hall wrote:

> OOP newbie on Python 2.6.

Python 2.6 is ancient, and is missing many nice features. You should consider
using the latest version, 3.6.


> I create instances of Character class with an attribute dict of
> 'skills'. The 'skills' dict has the name of a skill as the key and an
> int as a value. The code adds or modifies skills before outputting the
> Character.
> 
> Is it better design to have a Character.method that takes a 'skill' key
> and optional value or to have a general function that takes an instance,
> a dict, a key, and an optional value?

I'm afraid your example is too generic for me to give an opinion. Do you
literally mean a method called "method"? What does it do?



-- 
Steve
“Cheer up,” they said, “things could be worse.” So I cheered up, and sure
enough, things got worse.




More information about the Python-list mailing list