What is the most pythonic way to build up large strings?

Mark Lawrence breamoreboy at yahoo.co.uk
Sat Feb 8 08:34:38 EST 2014


On 08/02/2014 10:11, cstrutton11 at gmail.com wrote:
> On Saturday, February 8, 2014 3:13:54 AM UTC-5, Asaf Las wrote:
>
>>
>> note, due to strings are immutable - for every line in sum operation
>>
>> above you produce new object and throw out older one. you can write
>>
>> one string spanned at multiple lines in very clear form.
>>
>> /Asaf
>
> I think I going to rewrite this to build up a list of strings and then run a join on them at the end.  Each section can be conditionally built up with variable insertions as required.  This should be more efficient and will scale nicely as required.
>

An alternative is to use io.Stringio which is available in Python 2.7 
and 3.x.

Also would you please read and action this 
https://wiki.python.org/moin/GoogleGroupsPython to prevent us seeing the 
double line spacing above, thanks.

-- 
My fellow Pythonistas, ask not what our language can do for you, ask 
what you can do for our language.

Mark Lawrence

---
This email is free from viruses and malware because avast! Antivirus protection is active.
http://www.avast.com





More information about the Python-list mailing list