Python Equivalent for dd & fold
Michiel Overtoom
motoom at xs4all.nl
Thu Jul 16 11:34:25 EDT 2009
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
s="A very long string indeed. Really that long? Indeed."
fold(s,10)
--
"The ability of the OSS process to collect and harness
the collective IQ of thousands of individuals across
the Internet is simply amazing." - Vinod Valloppillil
http://www.catb.org/~esr/halloween/halloween4.html
More information about the Python-list
mailing list