[BangPypers] chaining string operations..
Senthil Kumaran
orsenthil at gmail.com
Fri Mar 25 11:01:08 CET 2011
On Fri, Mar 25, 2011 at 03:22:02PM +0530, Vishal wrote:
> I have a string that can be many megabytes worth memory size, and i
> want to
If you have got that string from a file like object, instead of
loading the entire string in memory you could iterate through the file
object to load one line at time. This will help provided the string is
has line-separators.
Otherwise you could store in a mock StringIO file like object and
iterate, if the string is heavy to handle in memory.
>
> Now I would like to chain these replacements into something like this:
>
> >>> s1 = s.replacements((' a', 'S'), (' \t', '\n'), ('C#', '\n')))
>
> Is there a known way of doing this currently in Python, apart from producing
Here is one recipe to do multiple string replacement in python in a
single shot.
http://uthcode.sarovar.org/pycon2010/strings.html#making-multiple-replacements-in-a-string-in-a-single-pass
--
Senthil
More information about the BangPypers
mailing list