def _wrap ( text , columns = 80 ) : out = [ ] for cnt , char in enumerate ( text ) : out . append ( char ) if ( cnt + 1 ) % columns == 0 : out . append ( "\n" ) return "" . join ( out )
python wrap (s,w) print
Own dumb reimplementation of textwrap . wrap () .
def _wrap(text, columns=80):
    """
    Own "dumb" reimplementation of textwrap.wrap().

    This is because calling .wrap() on bigger strings can take a LOT of
    processor power. And I mean like 8 seconds of 3GHz CPU just to wrap 20kB of
    text without spaces.

    Args:
        text (str): Text to wrap.
        columns (int): Wrap after `columns` characters.

    Returns:
        str: Wrapped text.
    """
    out = []
    for cnt, char in enumerate(text):
        out.append(char)

        if (cnt + 1) % columns == 0:
            out.append("\n")

    return "".join(out)