Processing a large string
nobody at nowhere.com
Fri Aug 12 06:11:40 CEST 2011
On Thu, 11 Aug 2011 19:03:36 -0700, goldtech wrote:
> Say I have a very big string with a pattern like:
> I want to split the sting into separate parts on the "3" and process
> each part separately. I might run into memory limitations if I use
> "split" and get a big array(?) I wondered if there's a way I could
> read (stream?) the string from start to finish and read what's
> delimited by the "3" into a variable, process the smaller string
> variable then append/build a new string with the processed data?
> Would I loop it and read it char by char till a "3"...? Or?
Use the .find() or .index() methods to find the next occurrence of a
Building a large string by concatenation is inefficient, as each append
will copy the original string. If you must have the result as a
single string, using cStringIO would be preferable. But you'd be better
off if you can work with a list of strings.
More information about the Python-list