"tanner barnes" wrote
I have a program with 2 classes and in one 4 variables
are created (their name, height, weight, and grade).
What im trying to make happen is to get the variables
from the first class and use them in the second class.
In general thats not a good idea. Each class should
tanner barnes wrote:
Ok so im in need of some help! I have a program with 2 classes and in
one 4 variables are created (their name, height, weight, and grade).
What im trying to make happen is to get the variables from the first
class and use them in the second class.
Indeed,
thanks for reminding me of that. The following should suffice:
class A:
def __init__(self):
self.height = 1
self.weight = 7
self.name = "tanner"
self.grade = "A"
class B:
def __init__(self, a):
self.info = [a.height, a.weight, a.name, a.grade]
prin
Python is not Java. Accessor methods are unnecessary and unidiomatic.
Just access the attributes directly.
For more on Python not being Java, see:
http://dirtsimple.org/2004/12/python-is-not-java.html
Cheers,
Chris
--
http://blog.rebertia.com
On Thu, Oct 22, 2009 at 10:07 PM, VYAS ASHISH M-NTB83
So What is stopping you to do this? Make some methods getName,
getHeight... and call classObj.getName() etc from other class.
Ashish
From: python-list-bounces+ntb837=motorola@python.org
[mailto:python-list-bounces+ntb837=motorola@python.org] On Behalf
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.heig