print with no newline

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


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



More information about the Python-list mailing list