All pastes #816360 Raw Edit

Anonymous

public text v1 · immutable
·published 2007-12-14 19:38 UTC
rendered paste body
def _get_selection(self, l, q = ""):
    "Returns the index of a user selection out of sequence l"
    selection = None
    while selection is None:
        if q:
            print q
        for i, obj in enumerate(l):
            print i, l
        
        try:
            selection = int(raw_input(">>>"))
        except ValueError:
            print "I'm sorry, you didn't type a valid index"
        else:
            try:
                l[selection]
            except IndexError:
                print "I'm sorry, you didn't type a valid index"
                selection = None
    return selection