"Eric Abrahamsen" <[EMAIL PROTECTED]> wrote
> The new problem is the while loop inside __upp. Every time I say
> "no", and it generates a new set of attributes, it seems to add
> another "layer" of unfinished = True, so that once I've got
> attributes I like, I need to say "yes" as many times as I said "no"
Welcome to the wacky world of recursion.
You call __upp from inside __upp so you do indeed generate
a new layer, in fact you start a new while loop. You need to
move the while loop out into init, something like this:
class Character(object):
def __init__(self):
happy = False
while not happy:
upp = _upp()
upp.showstats()
ok = raw_input('Happy now?[y/n] ')
if ok[0] in 'yY':
happy = True
def _upp(self):
# all the randrange stuff
self.career()
def career(self):
# all the career stuff
But actually I'd take the whole happy test stuff outside
the class entirely and make it a function:
def getCharacter():
happy = False
while not happy:
upp = Character()
upp.showstats()
ok = raw_input('Happy now?[y/n] ')
if ok[0] in 'yY':
happy = True
And the init becomes:
def __init__(self)
self._upp()
self._career()
That way the class only has to deal with creating an object
and is much more reusable.
Similarly for the career stuff, I'd put all the user interaction
outside the class and then pass some kind of parameter(s)
into the init method which passes them along to the career
method
def __init__(self, info=None)
self._upp()
if info == None:
info = self.getCareerInfo() # does the interaction stuff if
necessary
self._career(info)
HTH,
Alan G.
_______________________________________________
Tutor maillist - [email protected]
http://mail.python.org/mailman/listinfo/tutor