[Tutor] Dictionnaries in object

bob gailer bgailer at gmail.com
Thu Feb 24 20:17:05 CET 2011


On 2/24/2011 1:58 PM, Christopher Brookes wrote:
> Hi,
>
> I want to create some powers in my fight program.
> I want to know if dictionnaries is the best solution to do it.
>
> For now its look like this :
>
>
> //French name and description, don't care about it ;)
>
> power1= {}
> power1['Name'] = 'Flammes infernales'
> power1['Description'] = 'Embrase lenemi et le feu bruler'
>
> power2= {}
> power2['Name'] = 'Froid devorant'
> power2['Description'] = 'Gele lenemi sur place'
>
> powerAll= [power1,power2]
>
> but if i want to create like 20 powers, it will be long no ? is there 
> any solution shorter (and better ?)
>
1 - define a Power class and create instances

class Power:
   def __init__(self, name, desc):
     self.name = name
     self.desc = desc

powerAll = [
   Power('Flammes infernales' , 'Embrase lenemi et le feu bruler'),
   Power('Froid devorant', 'Gele lenemi sur place')]

-- 
Bob Gailer
919-636-4239
Chapel Hill NC



More information about the Tutor mailing list