how to suppress carriage return/line feed?

Bengt Richter bokr at oz.net
Wed Oct 30 15:28:57 EST 2002


On Wed, 30 Oct 2002 11:56:44 -0800, Erik Max Francis <max at alcyone.com> wrote:

>Bengt Richter wrote:
>
>> Did you add the trailing comma? The line above that mentions "desired
>> effect"
>> is only to preserve or not preserve the last of the non-scrolling
>> lines that
>> would precede it, when it all finishes.
>
>Using print, even with the trailing comma, is almost never a good idea
>when you're trying to do precision printing.  Using sys.stdout.write
>directly is almost always preferable in those cases.
>
>In particular, using print ..., will result in spurious spaces being
>printed, which will be especially troublesome when you're trying to
>overwrite the same line.
"Spurious" sounds buggy. They really are predictable. I was going to mention
softspace as the other way to control them, but since you have to go to
sys.stdout to do that anyway, you might as well use sys.stdout.write.

I think more troublesome than the print spaces will be if you don't use a
format that generates a fixed length output, whether you print it or pass it
to sys.stdout.write. In that case, if you move from a part of the program
that outputs a long message line to a part that outputs a short one,
you'll have (predictable ;-) spurious leftover trailing characters.

Your reminder to flush is a good idea ;-)

Regards,
Bengt Richter



More information about the Python-list mailing list