def greedyWrap(inString, width=80):

    outLines = []

    #eww, evil hacks to allow paragraphs delimited by two \ns :(
    if inString.find('\n\n') >= 0:
        paragraphs = inString.split('\n\n')
        for para in paragraphs:
            outLines.extend(greedyWrap(para, width) + [''])
        return outLines
    inWords = inString.split()

    column = 0
    ptr_line = 0
    while inWords:
        column = column + len(inWords[ptr_line])
        ptr_line = ptr_line + 1

        if (column > width):
            if ptr_line == 1:
                # This single word is too long, it will be the whole line.
                pass
            else:
                # We've gone too far, stop the line one word back.
                ptr_line = ptr_line - 1
            (l, inWords) = (inWords[0:ptr_line], inWords[ptr_line:])
            outLines.append(' '.join(l))

            ptr_line = 0
            column = 0
        elif not (len(inWords) > ptr_line):
            # Clean up the last bit.
            outLines.append(' '.join(inWords))
            del inWords[:]
        else:
            # Space
            column = column + 1
    # next word

    return outLines
Given a string and a column width, return a list of lines.
dataset/ETHPy150Open nlloyd/SubliminalCollaborator/libs/twisted/python/text.py/greedyWrap