What's the best way to write this base class?
Tim Chase
python.list at tim.thechases.com
Sat Jun 18 07:24:45 EDT 2011
More information about the Python-list mailing list
Sat Jun 18 07:24:45 EDT 2011
- Previous message (by thread): What's the best way to write this base class?
- Next message (by thread): What's the best way to write this base class?
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
On 06/18/2011 05:55 AM, bruno.desthuilliers at gmail.com wrote: > On 18 juin, 06:17, John Salerno<johnj... at gmail.com> wrote: >> class Character: >> >> base_health = 50 >> base_resource = 10 >> >> def __init__(self, name): >> self.name = name >> self.health = base_health >> self.resource = base_resource > > Did you at least tried this one ? Hint: it won't work. If you want it, you can use self.health = Character.base_health Though I'd treat them as semi-constants and capitalize them like your 3rd case: class Character(object): BASE_HEALTH = 50 ... def __init__(...): ... self.health = Character.BASE_HEALTH -tkc
- Previous message (by thread): What's the best way to write this base class?
- Next message (by thread): What's the best way to write this base class?
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
More information about the Python-list mailing list