How do I speedup this loop?

Steve nospam at nopes
Fri Jul 16 01:57:54 CEST 2004

Jean Brouwers wrote:
> What about handling all output as one string?
>     script = os.popen('some command')
>     script = script.replace("'", "\\'")  # replace ' with \'
>     script = script.replace("\r", ")  # remove cr
>     script = script.replace("\\n", "$___n")  # replace \n
>     script = script.replace("\n", "@___n'")  # replace nl

This won't do any better than what I was already doing. I need the code 
to be very fast and this will only end up creating a lot of copies 
everytime the string is going to be modified (strings are immutable). I 
really like the idea of using regex for this (proposed by lonnie), but I 
still need to a hang of it.


------------ And now a word from our sponsor ------------------
Want to have instant messaging, and chat rooms, and discussion
groups for your local users or business, you need dbabble!
--  See  ----

More information about the Python-list mailing list