Please hear my plea: print without softspace

Nick Patavalis npat at efault.net
Sat Feb 28 17:59:27 CET 2004


In article <edc2QLAGMJQAFwoM at jessikat.fsnet.co.uk>, Robin Becker wrote:
> 
> 
> ##############
> 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
> ##############

Would you perhaps care to comment a bit more, or provide a pointer to
some docs? It seems that there is a "softspace" atribute in the
sys.stdout file object, and that this attribute gets set by the print
statement itself. With your clever trick you make it imposible for
someone to set this attribute to anything else but "False". What are
the exact semantics behind this?

I tried this:

  import sys
  print sys.stdout.softspace
  0
  print "test:", 1, 2, 3, sys.stdout.softspace
  test: 1 2 3 1
  print sys.stdout.softspace
  0

Which seems to support my explanation, but what exactly are the
semantics of "softspace"?

Thanks
/npat





More information about the Python-list mailing list