Re: Controlling output using print with format string
Available news archives: comp.lang.tcl - comp.lang.python - comp.security.firewalls - sci.crypt - comp.lang.php - comp.lang.javascript
Google
 
Web news.hping.org


comp.lang.python archive

Re: Controlling output using print with format string

From: Alex Martelli <aleaxit@yahoo.com>
Date: Mon Oct 31 2005 - 01:15:01 CET

Paul Watson <pwatson@redlinepy.com> wrote:

> It is clear that just using 'print' with variable names is relatively
> uncontrollable. However, I thought that using a format string would
> reign the problem in and give the desired output.
>
> Must I resort to sys.stdout.write() to control output?

In general, yes, because print tries hard to separate with spaces the
things it is separately printing. You can fight that by resetting
sys.stdout.softspace after each and every print, but that's harder than
just using sys.stdout.write. So, you should use the right tool for the
job: print for simple output, often diagnostic in nature, where you
don't mind the spaces and/or newlines that implies; sys.stdout.write
when you do want to really control every aspect of the output.

Alex
Received on Mon Nov 21 01:06:33 2005