Again: Please hear my plea: print without softspace

Martin Bless m.bless at
Wed Mar 3 10:47:17 CET 2004

[David Goodger <goodger at>]

>you should write a PEP.  Without a PEP, the idea will be forgotten.

Good advice, good encouragement, thanks.

I'd really like to. But unfortunately I've discovered the weak point
in my own argumentation: a new keyword could and probably would break
existing code. Therefore I can't go for a PEP until I have a better

Ok, then let's use some wrappers or helper functions. Here's the one I
currently like:

#!/usr/bin/env python
# -*- coding: iso-8859-1 -*-
"""Do some experiments on write statements."""

__author__ = "Martin Bless, 2004-03-03"

class Writer:

    def __init__(self,writer=None):
        if writer is None:
            import sys
            self.writer = sys.stdout
            self.writer = writer

    def write(self,*args):
        for arg in args:

    __call__ = write

    def to(self,writer,*args):
        for arg in args:

write = Writer()
NL = '\n'
import sys
stderr = Writer(sys.stderr)

if __name__=="__main__":
    import sys
    outfile = sys.stdout or file('demo_tempfile','w')
    write('#', '-->'*10, NL)
    write("write(1,2,3,4,NL)=>", 1,2,3,4,NL)
    write("write('This',' ','is',' ','a',' ','demo.',NL)=>",
          'This',' ','is',' ','a',' ','demo.',NL) outfile,",5,6,7,8,NL)=>",5,6,7,8,NL)
    stderr("stderr('A number in parentheses: (', 77, ').', NL)=>",
           'A number in parentheses: (',77,').',NL)
    write('#', '<--'*10, NL)

    """Output should be:
Do some experiments on write statements.
write('This',' ','is',' ','a',' ','demo.',NL)=>This is a demo.,5,6,7,8,NL)=>5678
stderr('A number in parentheses: (',77,').',NL)=>A number in
parentheses: (77).

This comes pretty close to what I was aiming at. But of course it's
just my version and different people will create different solutions.

mb - Martin Bless

More information about the Python-list mailing list