Again: Please hear my plea: print without softspace

David MacQuigg dmq at gain.com
Tue Mar 2 18:32:35 CET 2004


On Mon, 01 Mar 2004 21:42:21 GMT, "Rainer Deyke" <rainerd at eldwood.com>
wrote:

>Josiah Carlson wrote:
>> The right thing to do (if it were to happen at all) is to make
>> fileobject.softspace "sticky" under some condition, perhaps after a
>> call to fileobject.SetSoftSpace(False) (which doesn't currently
>> exist).
>
>The right thing to do is to put make stdout a builtin and deprecate the
>print statement.  The "smart" behavior of the print statement causes more
>trouble than it's worth.  I admit that I use the print statement myself
>occasionally, but only because 'sys.stdout.write' is too long to type all
>the time, and never with more than one argument.

The 'print' statement is just shortcut for 'sys.stdout.write' with
some convenience features suitable for most users.  If you need
something else, just define your own shortcut, don't deprecate a
statement that is exactly what most users want.

>>> wrt = sys.stdout.write
>>> wrt('abc'); wrt('xyz\n'); wrt('abc'); wrt('xyz')
abcxyz
abcxyz

Now you have explicit control over the \n, and the new statement
(including parens) is the same number of characters as 'print'.

We need to resist the temptation to *change* the core language, when
*extending* it using normal function syntax is so easy.

Note: You can also change the behavior of 'print' by redefining
'sys.stdout.write'.  You can even hide that redefinition deep in some
imported module, where future maintainers of your code will never find
it. :>)

-- Dave




More information about the Python-list mailing list