On Thu, Oct 22, 2009 at 11:59 PM, Kenny Shen <[email protected]> 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
_______________________________________________
Tutor maillist - [email protected]
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor