[Tutor] Help with my program
Kent Johnson
kent37 at tds.net
Fri Oct 23 15:08:20 CEST 2009
On Thu, Oct 22, 2009 at 11:59 PM, Kenny Shen <littlemog at gmail.com> wrote:
> Hi tanner,
>
> I suppose the following is possible:
>
> class A:
> def __init__(self):
> self.height = 1
> self.weight = 7
> self.name = "tanner"
> self.grade = "A"
> def getinfo(self):
> info = []
> info.append(self.name)
> info.append(self.weight)
> info.append(self.height)
> info.append(self.grade)
> return info
>
> class B:
> def __init__(self, a):
> self.info = a.getinfo()
> print self.info
You don't need A.getinfo(). Just have B.__init__() keep a reference to
its 'a' in an attribute:
class B:
def __init__(self, a):
self.a = a
Then in any methods of B you can refer to self.a.height, etc.
Kent
More information about the Tutor
mailing list