newbie question: getting rid of space in string :(

Martin Franklin mfranklin1 at gatwick.westerngeco.slb.com
Fri Jul 12 14:49:50 EDT 2002


On Friday 12 Jul 2002 5:30 pm, Alex Martelli wrote:
> Martin Franklin wrote:
>         ...
>
> > as a matter of taste I would use this:-
> > wholeString=wholeString+"<%s><b>%s</b></%s>" %(color, a, color)
> > but as I say this is a matter of taste!
>
> Building up a large string by + concatenation of many
> small ones is Python's main performance trap.  If you
> want to build things up, build them up in a list instead,
> then at the end you can use sys.stdout.writelines to write
> it out or ''.join to make the big string.



I agree. I guess I was giving the OP what I consider the simplest way 
(without introducing anything too 'new' to him (he did say he was a newbie) 

Best Regards
Martin





More information about the Python-list mailing list