print with no newline

Jp Calderone exarkun at divmod.com
Fri Sep 3 10:54:03 EDT 2004


Paul Watson wrote:
> "Jp Calderone" <exarkun at divmod.com> wrote in message
> news:mailman.2834.1094220495.5135.python-list at python.org...
> 
>>Paul Watson wrote:
>>
>>>I thought that using a comma at the end of a print statement would
> 
> suppress
> 
>>>printing of a newline.  Am I misunderstanding this feature?  How can I
> 
> use
> 
>>>print and not have a newline appended at the end?
>>>
>>
>>   Print doesn't want to leave the *final* line without a newline.
>>sys.stdout.write() doesn't care if your shell prompt gets mixed in with
>>the last line of output.  You'll need to use the latter if that's what
>>you want.
>>
>>exarkun at boson:~$ python -c "import sys; sys.stdout.write('here')"
>>hereexarkun at boson:~$
>>
>>   Jp
> 
> 
> Ok, I can use sys.stdout.write().  Still, this comma at the end thing does
> not seem very consistent.  Before the last line, while it does suppress the
> newline, a space is still added to the output.  Why is that?  Yes, I have
> seen spaces added between items in the print statement and, while it is
> probably convenient at times, is frequently an annoyance.

   Basically, print is only meant to help people new to the language get 
started ;)  It often does what will make life easiest for someone who is 
just getting into things, but which is otherwise confusing, expected, 
special-casey, or otherwise undesirable.  I mean, the whole existence of 
the keyword "print" is an inconsistency, right?  One could quite 
reasonably expect print to be a function.

   Jp



More information about the Python-list mailing list