string concatenation

Scott David Daniels Scott.Daniels at Acm.Org
Fri Jul 2 16:23:23 CEST 2004

Ajay wrote:
> for name in contextForm.keys():
>     context += "Input: " + name + " value: " + contextForm[name].value +
> "<BR>"
> context is meant to hold all the form values in the paper.
Although the 'collect in a list, join at leisure' plan often is best,
don't forget StringIO.  This situation is tailor-made for StringIO.

     from cStringIO import StringIO

     dest = StringIO()
     for name in contextForm.keys():
         print >>dest, 'Input:', name, 'value:', contextForm[name].value,
         print >>dest, '<BR>'
     whatever = dest.getvalue()

-Scott David Daniels
Scott.Daniels at Acm.Org

More information about the Python-list mailing list