# http://www.norvig.com/python-iaq.html
h = [None]  # history

class Prompt:
    """
    A prompt a history mechanism.
    From http://www.norvig.com/python-iaq.html
    """
    def __init__(self, prompt='h[%d] >>> '):
        self.prompt = prompt

    def __str__(self):
        try:
            if _ not in h: h.append(_)
        except NameError:
            pass
        return self.prompt % len(h)

    def __radd__(self, other):
        return str(other) + str(self)
