how to save strings to a temporary buffer?

Steve Holden sholden at holdenweb.com
Wed Jul 18 15:14:15 EDT 2001


<ed_tsang at yahoo.com> wrote in message
news:mailman.995481031.2700.python-list at python.org...
> How can I save string to a tempororay buffer and then write it to a
> file afterwards?
>
> I have a function that output a formatted string each time it is
> called; but instead of open a file and write it each time; I would
> like to save these strings to a , may be a tmeporory buffer, and then
> write it to a file when everythign is completed... how cna I do that?
> thansk
>
You could just accumulate the strings in a list: pass the current list to
the function and have it append() its current output. Then just write all
the strings out at the end of the program.

Or look at the StringIO or cStringIO modules.

regards
 Steve
--
http://www.holdenweb.com/








More information about the Python-list mailing list