[Tutor] Tutor Digest, Vol 88, Issue 86

Alan Gauld alan.gauld at btinternet.com
Wed Jun 22 01:43:05 CEST 2011


"David Merrick" <merrickdav at gmail.com> wrote

>I have created a Critter object and a Farm object which is two 
>critters. I
> want to use Critters methods in the Farm object as it just 2 
> critters in a
> list
>
> crit1 = Critter("Sweetie")
> crit2 = Critter("Dave")
> farmlet = [crit1,crit2]
>

This creates two critters but it does not create a Farm object,
it only creates a list of two critters. (That might be all you need!
Maybe you don't need a Farm class)

So to call the talk() method of crit1 via the farmlet list:

farmlet[0].talk()

Or for all the critters in the farmlet:

for critter in farmlet:
     critter.talk()

HTH,

-- 
Alan Gauld
Author of the Learn to Program web site
http://www.alan-g.me.uk/




More information about the Tutor mailing list