[Tutor] Display all field of a listuples
bob gailer
bgailer at gmail.com
Fri Feb 25 05:23:54 CET 2011
On 2/24/2011 4:54 PM, Christopher Brookes 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)
>
> class Power:
> def __init__(self, name, desc):
> self.name <http://self.name> = name
> self.desc = desc
>
>
>
>
> powerAll = [
> Power('Flammes infernales' , 'Embrase lenemi et le feu bruler'),
> Power('Froid devorant', 'Gele lenemi sur place')]
>
>
> But he won't display it :(
>
> i've try For PowerName,PowerDesc in powerAll:
> print (PowerName, PowerDesc)
>
> but it doesn't work !
When something "does not work" always show us what results you got as
well as what you wanted.
Also get in the habit of using Capitalized names for classes and
unCapitalized names for variables and functions.
powerAll is a list of class instaces. You must (in some way) identify
the attributes of those instances. One way:
for power in powerAll:
print (power.name, power.desc)
--
Bob Gailer
919-636-4239
Chapel Hill NC
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20110224/2411b89f/attachment.html>
More information about the Tutor
mailing list