Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #58824

chunking a long string?

From Roy Smith <roy@panix.com>
Date 2013-11-08 12:48 -0500
Subject chunking a long string?
Newsgroups comp.lang.python
Message-ID <mailman.2232.1383932895.18130.python-list@python.org> (permalink)

Show all headers | View raw


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

Back to comp.lang.python | Previous | NextNext in thread | Find similar | Unroll thread


Thread

chunking a long string? Roy Smith <roy@panix.com> - 2013-11-08 12:48 -0500
  Re: chunking a long string? wxjmfauth@gmail.com - 2013-11-08 12:43 -0800
    Re: chunking a long string? Chris Angelico <rosuav@gmail.com> - 2013-11-09 07:53 +1100
    Re: chunking a long string? Mark Lawrence <breamoreboy@yahoo.co.uk> - 2013-11-08 20:57 +0000
    Re: chunking a long string? Tim Chase <python.list@tim.thechases.com> - 2013-11-08 15:04 -0600
    Re: chunking a long string? Mark Lawrence <breamoreboy@yahoo.co.uk> - 2013-11-08 21:06 +0000
    Re: chunking a long string? Chris Angelico <rosuav@gmail.com> - 2013-11-09 08:04 +1100
    Re: chunking a long string? Chris Angelico <rosuav@gmail.com> - 2013-11-09 08:17 +1100
    Re: chunking a long string? Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2013-11-09 00:46 +0000
      Re: chunking a long string? wxjmfauth@gmail.com - 2013-11-09 00:14 -0800
        Re: chunking a long string? Chris Angelico <rosuav@gmail.com> - 2013-11-09 19:26 +1100
          Re: chunking a long string? Roy Smith <roy@panix.com> - 2013-11-09 09:37 -0500
            Re: chunking a long string? Chris Angelico <rosuav@gmail.com> - 2013-11-10 02:02 +1100
              Re: chunking a long string? Roy Smith <roy@panix.com> - 2013-11-09 10:21 -0500
                Re: chunking a long string? Chris Angelico <rosuav@gmail.com> - 2013-11-10 02:30 +1100
                Re: chunking a long string? Roy Smith <roy@panix.com> - 2013-11-09 10:35 -0500
            Re: chunking a long string? Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2013-11-09 15:37 +0000
              Re: chunking a long string? Chris Angelico <rosuav@gmail.com> - 2013-11-10 09:14 +1100
                Re: chunking a long string? Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2013-11-10 06:39 +0000
                Re: chunking a long string? Chris Angelico <rosuav@gmail.com> - 2013-11-10 19:46 +1100
        Re: chunking a long string? Mark Lawrence <breamoreboy@yahoo.co.uk> - 2013-11-09 10:13 +0000
  Re: chunking a long string? Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2013-11-09 00:54 +0000

csiph-web