string concatentation

Marcin 'Qrczak' Kowalczyk qrczak at knm.org.pl
Sun Apr 1 09:29:59 EDT 2001


Sun, 01 Apr 2001 12:21:00 GMT, Tony Rentschler <tonyr at walterr.bellatlantic.net> pisze:

> My first thought was to do something like this:
> big_string = big_string + new_string.
> 
> In practice, will this be inefficient?

Yes.

> That is, will Python malloc a new big_string each time I add a line?

Yes.

> Is there another way to handle this sort of situation,

Yes: e.g. append strings to a list and join them at the end
(using string.join or Python-2.0's ''.join(list)), or use the
cStringIO module.

-- 
 __("<  Marcin Kowalczyk * qrczak at knm.org.pl http://qrczak.ids.net.pl/
 \__/
  ^^                      SYGNATURA ZASTĘPCZA
QRCZAK



More information about the Python-list mailing list