help needed with class and method confusion
Pierre Quentel
quentel.pierre at wanadoo.fr
Tue Jan 6 16:56:57 EST 2004
If I understand the problem, you have a planet and a number of moons turning
around it. So you should define two different classes, Planet and Moon
--------------------------------
class Moon:
def __init__(self, name):
self.name = name
class Planet:
def __init__(self,names):
self.moons = []
for name in names:
m=Moon(name)
setattr(self, name, m)
self.moons.append(m)
satellites = ["Io", "Europa", "Ganymeade"]
Jupiter = Planet(satellites)
-------------------------------
You'd better leave the satellite names outside of the __init__ method of
Planet,
in case you happen to work on another planet
Hope this helps,
Pierre
More information about the Python-list
mailing list