Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!newsfeed.xs4all.nl!newsfeed1.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.006 X-Spam-Evidence: '*H*': 0.99; '*S*': 0.00; '"this': 0.03; 'string': 0.09; 'iterate': 0.09; 'subject:string': 0.09; 'chunks': 0.16; 'itertools': 0.16; 'manageable': 0.16; 'received:166.84': 0.16; 'received:166.84.1': 0.16; 'received:166.84.1.89': 0.16; 'received:24.136': 0.16; 'received:mailbackend.panix.com': 0.16; 'received:panix.com': 0.16; 'roy': 0.16; 'to:name:python list': 0.16; 'do,': 0.16; 'received:166': 0.19; 'seems': 0.21; '---': 0.24; 'received:24': 0.27; 'character': 0.29; 'getting': 0.31; 'something': 0.35; 'but': 0.35; 'there': 0.35; 'edge': 0.36; 'charset:us-ascii': 0.36; 'subject:?': 0.36; 'should': 0.36; 'example,': 0.37; 'to:addr:python-list': 0.38; 'to:addr:python.org': 0.39; 'worry': 0.60; 'header:Message-Id:1': 0.63; 'anything.': 0.68; 'smith': 0.68; 'email addr:panix.com': 0.84; 'subject:long': 0.84 From: Roy Smith Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: quoted-printable Date: Fri, 8 Nov 2013 12:48:12 -0500 Subject: chunking a long string? To: Python List Mime-Version: 1.0 (Apple Message framework v1283) X-Mailer: Apple Mail (2.1283) X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 17 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1383932895 news.xs4all.nl 15962 [2001:888:2000:d::a6]:49213 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:58824 I have a long string (several Mbytes). I want to iterate over it in = manageable chunks (say, 1 kbyte each). For (a small) example, if I = started with "this is a very long string", and I wanted 10 character = chunks, I should get: "this is a " "very long " "string" This seems like something itertools would do, but I don't see anything. = Is there something, or do I just need to loop and slice (and worry about = getting all the edge conditions right) myself? --- Roy Smith roy@panix.com