Michiel Overtoom wrote:
seldan24 wrote:
I know that Emile suggested that I can slice out the substrings rather
than do the gradual trimming of the string variable as is being done
by moving around the length.
An excellent idea.

def fold(s,chunklength):
    offset=0
    while offset<len(s):
        print s[offset:offset+chunklength]
        offset+=chunklength

More Pythonic:

    for offset in range(0, len(s), chunklength):
        print s[offset : offset + chunklength]

s="A very long string indeed. Really that long? Indeed."
fold(s,10)

--
http://mail.python.org/mailman/listinfo/python-list

Reply via email to