Again: Please hear my plea: print without softspace

Gerrit gerrit at nl.linux.org
Tue Mar 2 11:21:51 EST 2004


Josiah Carlson wrote:
> It seems that you are saying:
> 
> print "hello ", "world" +   #-> "hello world"
> 
> That looks like "magic syntax", and should rightfully return a syntax 
> error, because + already has a meaning for most all data types in 
> Python.  Changing the behavior of print when a syntax error is present, 
> is the wrong thing to do.

It can be done the other way around:
>>> class Mystr(str):
...  def __pos__(self):
...   if self.endswith(' '): return self[:-1]
...   else: return self
...
>>> m = Mystr("abc ")
>>> print +m, "bla"
abc bla

...although I prefer sys.stdout.write.

Gerrit.

-- 
Weather in Twenthe, Netherlands 02/03 14:55 UTC:
	6.0°C Few clouds mostly cloudy wind 5.8 m/s WNW (57 m above NAP)
-- 
Asperger's Syndrome - a personal approach:
	http://people.nl.linux.org/~gerrit/english/




More information about the Python-list mailing list