def execute(self, pos, end = None):
        """execute history number from pos to end"""
        length = get_current_history_length()
        if length > 1:
            if pos >= length - 1:
                pos = length - 1
            elif pos < 1:
                pos = length + pos - 1
            if not end:
                end = pos + 1
            elif end >= length:
                end = length
            if end < 0:
                end = length + end
            else:
                end = end + 1

            to_execute = map(get_history_item, xrange(pos, end))

            filename = mktemp()
            fp = open(filename, 'w')
            write = fp.write
            map(lambda x: write('%s\n' % x), to_execute.__iter__())
            fp.close()

            try:
                execfile(filename, __main__.__dict__)
                read_history_file(filename)
                remove(filename)
            except:
                remove(filename)
execute history number from pos to end
recipes/Python/496822_Completer_history_viewer_support_more/recipe-496822.py