def string_splitter(input_str, max_length=40):
    """
    Returns a string that is the input string but with \n inserted every max_length chars

    :param input_str:
    :param max_length: int num of chars between \n
    :return: string
    """

    chunks = []
    chunk = ''
    pieces = input_str.split(' ')

    for piece in pieces:
        if len(chunk) + len(piece) < max_length:
            chunk = ' '.join([chunk, piece])
        else:
            chunks.append(chunk)
            chunk = piece
    chunks.append(chunk)

    return '\n'.join(chunks).strip()