[Tutor] Display all field of a listuples

Christopher Brookes chris.klaitos at gmail.com
Fri Feb 25 00:02:06 CET 2011


class Character:
       def __init__(self, name):
        self.name = name

    def ChoosePouvoirUnique(self):
        """ Permet de choisir le pouvoir unique du personnage """
        print ("Veuillez choisir votre pouvoir unique dans la liste")


        for PowerNom,PowerDesc in powerAll:
            print (PowerNom, PowerDesc)


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')]

hero1 = Character("Klaitos")
hero1.ChoosePouvoirUnique()

im *WANT to display this* :

Froid devorant : Gele lenemi sur place
Flammes infernales : Embrase lenemi et le feu bruler

I don't know how to get this ? :(

2011/2/24 Steven D'Aprano <steve at pearwood.info>

> Alex Hall wrote:
>
>> On 2/24/11, Christopher Brookes <chris.klaitos at gmail.com> wrote:
>>
>>>  Hi i would like to display all the field of my powerAll like this :
>>>
>>> Choose a power :
>>> Froid devorant : Embrase lenemi et le feu bruler
>>> Flammes infernales : 'Gele lenemi sur place
>>>
>>> -----------------------------
>>> class Character():
>>>  def ChoosePouvoirUnique(self):
>>>        print ("Choose a power")
>>>        for Power in powerAll:
>>>            print (Power)
>>>
>>
>  You need a __init__() function in this class, as with any class.
>>
>
> That's not strictly correct. You don't *need* an __init__ method, unless
> your class needs to be initialised. Most classes will, but some do not.
>
>
> [...]
>
>  Also, "for" should be lowercase, though I am
>> honestly not sure that this is a requirement(though I believe it is).
>>
>
> It certainly is. Python is case sensitive, so "for" and "FOR" and "For" are
> different. "for" is a Python keyword with special meaning. The others are
> just words with no special meaning.
>
>
>
>
> --
> Steven
>
> _______________________________________________
> Tutor maillist  -  Tutor at python.org
> To unsubscribe or change subscription options:
> http://mail.python.org/mailman/listinfo/tutor
>



-- 
Brookes Christopher.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20110225/412f0141/attachment.html>


More information about the Tutor mailing list