string concatentation

Tony Rentschler tonyr at walterr.bellatlantic.net
Sun Apr 1 08:21:00 EDT 2001


I'm writing a program that reads individual lines of text from stdin, which
is filled by piping the output from another program into mine. I need
to collect the individual lines I've read into one large string. My first
thought was to do something like this: big_string = big_string + new_string.

In practice, will this be inefficient? That is, will Python malloc a new
big_string each time I add a line? Is there another way to handle this sort
of situation, say with a pre-allocated buffer of some kind?

Thanks,
Tony

-- 
Tony Rentschler         Senior Software Engineer
The Associated Press    50 Rockefeller Plaza
New York, NY 10020      (212) 621-1985
trentschler at ap.org



More information about the Python-list mailing list