Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #58830 > unrolled thread
| Started by | Skip Montanaro <skip@pobox.com> |
|---|---|
| First post | 2013-11-08 12:04 -0600 |
| Last post | 2013-11-08 12:04 -0600 |
| Articles | 1 — 1 participant |
Back to article view | Back to comp.lang.python
This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by
below is the oldest one visible, not the original post.
Re: chunking a long string? Skip Montanaro <skip@pobox.com> - 2013-11-08 12:04 -0600
| From | Skip Montanaro <skip@pobox.com> |
|---|---|
| Date | 2013-11-08 12:04 -0600 |
| Subject | Re: chunking a long string? |
| Message-ID | <mailman.2237.1383933900.18130.python-list@python.org> |
> I have a long string (several Mbytes). I want to iterate over it in manageable chunks (say, 1 kbyte each). You don't mention if the string is in memory or on disk. If it's in memory: >>> for i in range(0, len(s), 10): ... print repr(s[i:i+10]) ... 'this is a ' 'very long ' 'string' If your string is on disk, just loop over an open file object, reading your chunk size every pass of the loop. Skip
Back to top | Article view | comp.lang.python
csiph-web