[Tutor] buffering print statement
Alan Gauld
alan.gauld at blueyonder.co.uk
Thu Dec 18 17:18:04 EST 2003
> Is there a simple way of redirecting the output of
> 'print' statements in a script, until such time as I
> actually want them sent to stdout, and they can all be
> sent at once?
Umm, I may be missing something but that sounds like a
string variable? Just send formatted strings to a string
variable, then at the end print the string...
buffer = "Hello world\n"
foo = 27 + 42
buffer += str(foo) + '\n'
etc/...
print buffer
You could even write a short function (printbuff, say)
to take care of adding newlines etc.
Or is there something else you want to do?
Alan G.
More information about the Tutor
mailing list