S. Staats <ss*****@questi a.com> wrote:
Good day, everbody.
Here is a simple program called test.py:
#!/usr/bin/python
print "No newline, please.",
# End of program
Here is what program does:
prompt> ./test.py
No newline, please.
Here is what I want the program to do:
prompt> ./test.py
No newline, please.prompt>
How can I get the python interpreter to not print a newline when it exits?
You can avoid using print -- use sys.output.writ e instead -- or you can
use sys.output.soft space=False as the last statement in your program.
The reason for the newline is that, when standard output (sys.output) is
closed, it checks if its softspace attribute is True (meaning there is a
pending line not yet terminated) and if so terminates the line. In
turn, softspace is set by print with a trailing comma, specifically to
avoid erroneously-unterminated lines (and other small anomalies). So,
if you want something a bit out of the ordinary such as an unterminated
line being output, either you eschew print, which is meant to help in
typical ordinary cases (sys.stdout.wri te being there for when you need
fine control), or you reset that special attribute to False.
Alex