Please hear my plea: print without softspace

Robin Becker robin at jessikat.fsnet.co.uk
Sat Feb 28 08:09:26 EST 2004


In article <dca1dc79fa2d9efd5bb586b079d4db53.46955 at mygate.mailgate.org>,
Carmine Noviello <cnoviello at hotmail.com> writes
>def pprint(*args):
>    txt = ""
>    for a in args:
>       txt += str(a)
>    print txt
>
>Is it ok?
>
>-- 
>Don't you know why your Python application has crashed? 
>Take a look to http://www.pycrash.org
>
>
Give stdout a good hiding :)

##############
class hidesoftspace:
    def __init__(self,fobj):
        self.__dict__['_fobj'] = fobj
        fobj.softspace = False
    def __getattr__(self,a):
        if a=='softspace': return False
        return getattr(self._fobj,a)
    def __setattr__(self,a,v):
        if a=='softspace': return
        setattr(self._fobj,a,v)

import sys
print 'before hiding',1,2,3,4
sys.stdout=hidesoftspace(sys.stdout)
print 'after  hiding',1,2,3,4
##############
results in

before hiding 1 2 3 4
after  hiding1234
-- 
Robin Becker



More information about the Python-list mailing list