Again: Please hear my plea: print without softspace

rzed rzantow at ntelos.net
Mon Mar 1 23:50:10 EST 2004


Josiah Carlson <jcarlson at nospam.uci.edu> wrote in
news:c209n0$cit$1 at news.service.uci.edu: 

>> I've wondered, though, whether there couldn't be a different 
>> character instead of a ',' to alter the behavior of print.
>> Maybe a trailing '+' to indicate that what follows is to
>> concatenate directly. 
>> 
>> And yet I've been able to work around that little annoyance;
>> it's not that there is no way to format output the way you
>> want. 
> 
> 
> 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.
> 
> 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). 
>

I'm not sure I agree with this entirely. The comma following a 
print statement is a sort of magic syntax as it is; it changes the 
behavior of the unadorned print statement in a way that has very 
little to do with any syntactical meaning a comma would normally 
have. The idle thought I mentioned above would just use a different 
symbol to alter the behavior of print in a slightly different 
fashion. What I actually had in mind, adapting your example, was 
something a little different:
print "hello" + 
print "nwheels"  #-> "hellonwheels" 

If a '+' is problematic, it could be some other character. If I use 
a print statement in a Python program, from my viewpoint, a 
trailing comma signals suppression of newline and adding a space. 
In this scenario, a trailing <insert acceptable character here> 
would suppress the newline but not add a space. There's not much 
difference there.

Having said all that, I'll add that I don't see this as a big 
issue, and I don't find it a burden to use an alternative syntax to 
achieve the same effect. I don't know how to tell if it's a right 
or wrong thing to do. If it were a feature of the language, I'd 
probably use it. I've never really understood what it is about the 
print statement that bothers some people; it's always seemed 
reasonably useful and reasonably intuitive to me. Maybe every 
language is destined to have irregular verbs.
 

-- 
rzed




More information about the Python-list mailing list