print with no newline
Paul Watson
pwatson at redlinepy.com
Fri Sep 3 10:44:58 EDT 2004
"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.
C:\src\projects\test1>python -c "print 'here',;print 'there'," >jjj
C:\src\projects\test1>od -c -tx1 jjj
0000000 h e r e t h e r e \r \n
68 65 72 65 20 74 68 65 72 65 0d 0a
0000014
More information about the Python-list
mailing list