def choose(msg, items, attr):  
<EOL>if len(items) == <NUM_LIT:1>:<EOL><INDENT>return items[<NUM_LIT:0>]<EOL><DEDENT>print()<EOL>for index, i in enumerate(items):<EOL><INDENT>name = attr(i) if callable(attr) else getattr(i, attr)<EOL>print('<STR_LIT>' % (index, name))<EOL><DEDENT>print()<EOL>while True:<EOL><INDENT>try:<EOL><INDENT>inp = input('<STR_LIT>' % msg)<EOL>if any(s in inp for s in ('<STR_LIT::>', '<STR_LIT>', '<STR_LIT:->')):<EOL><INDENT>idx = slice(*map(lambda x: int(x.strip()) if x.strip() else None, inp.split('<STR_LIT::>')))<EOL>return items[idx]<EOL><DEDENT>else:<EOL><INDENT>return items[int(inp)]<EOL><DEDENT><DEDENT>except (ValueError, IndexError):<EOL><INDENT>pass<EOL><DEDENT><DEDENT>
Command line helper to display a list of choices, asking the
        user to choose one of the options.