Steven D'Aprano a écrit :
> On Sun, 04 Feb 2007 17:45:04 +0100, Mizipzor wrote:
>
>
>>Consider the following snippet of code:
>>
>>class Stats:
>>def __init__(self, speed, maxHp, armor, strength, attackSpeed,
imagePath):
>>self.speed = speed
>>self.maxHp = maxHp
>>
On Sun, 04 Feb 2007 17:45:04 +0100, Mizipzor wrote:
> Consider the following snippet of code:
>
> ==
>
> class Stats:
> def __init__(self, speed, maxHp, armor, strength, attackSpeed, imagePath):
> self.speed = speed
> self.maxHp = maxHp
> self.
Mizipzor wrote:
> class Stats:
> def __init__(self, *li):
> self.speed = li[0]
> self.maxHp = li[1]
> (...)
>
> Or maybe there is an even niftier way that lets me iterate through
> them?
Using keyword arguments instead of positional parameters makes this easy:
>>> class
Mizipzor <[EMAIL PROTECTED]> wrote in
news:[EMAIL PROTECTED]:
> Consider the following snippet of code:
>
> ==
>
> class Stats:
> def __init__(self, speed, maxHp, armor, strength,
> attackSpeed, imagePath):
> self.speed = speed
> self.maxHp = max
Mizipzor
> I dont like the looks of that code, there are many
> function parameters to be sent in and if I were to add an attribute, i
> would need to add it in three places. Add it to the function
> parameters, add it to the class and assign it.
> Is there a smoother way to do this?
You may use s
Consider the following snippet of code:
==
class Stats:
def __init__(self, speed, maxHp, armor, strength, attackSpeed, imagePath):
self.speed = speed
self.maxHp = maxHp
self.armor = armor
self.strength = strength
self.attackSpeed