473,555 Members | 2,506 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How does one keep python from printing newline at program exit?

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?

Thanks for your help!
Jul 18 '05 #1
2 2651
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
Jul 18 '05 #2
S. Staats 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?

Thanks for your help!


sys.stdout.writ e('No newline, please')
Jul 18 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

16
2570
by: Jason | last post by:
Hey, I'm an experience programmer but new to Python. I'm doing a simple implementation of a field morphing techinique due to Beier and Neely (1992) and I have the simple case working in Python 2.3 - but it's REALLY slow. Basically, you specify two directed line segments in the coordinate system of a raster image and use the difference...
1
1401
by: Yong Wang | last post by:
Hi, All: I try to write a CGI script to post network traffic routing info in the web page. I have successfully obtained traffic info from wraped python with C++ and MYSQL and SNMP code and output to a file. I need read a file which contain traffic info and post to web. In CGI script, I use: file=open('/apps/www/htdocs/internal/nd/output1',...
13
2973
by: Grant Edwards | last post by:
A few months back I wrote a sort of a strip-chart recorder program that talks DeviceNet to a measurement widget and plots the received data in more-or-less real time using the Gnuplot module. It was written on Linux system with absolutely no thought given to portability. It's nothing big (about 650 lines of code). Today, just for fun, I...
12
2297
by: Fred Pacquier | last post by:
First off, sorry for this message-in-a-bottle-like post... I haven't been able to phrase my questions well enough to get a meaningful answer from Google in my research. OTOH, it is standard flattery (but true) that this group has a bunch of the nicest and most knowledgeable Usenet people around, and I know for a fact that there are some pretty...
20
7880
by: TTroy | last post by:
Hello, I have found some peculiar behaviour in the fgets runtime library function for my compiler/OS/platform (Dev C++/XP/P4) - making a C console program (which runs in a CMD.exe shell). The standard says about fgets: synopsis #include <stdio.h> char *fgets(char *s, int n, FILE *stream);
1
2076
by: sri2097 | last post by:
Hi all, I have written a Link list implementation in Python (Although it's not needed with Lists and Dictionaries present. I tried it just for the kicks !). Anyway here is the code - # Creating a class comprising of node in Link List. class linklist: def __init__(self, data=None,link=None): self.data = data self.link = link
0
263
by: Kurt B. Kaiser | last post by:
Patch / Bug Summary ___________________ Patches : 431 open ( +3) / 3425 closed ( +8) / 3856 total (+11) Bugs : 916 open (-23) / 6273 closed (+44) / 7189 total (+21) RFE : 244 open ( +4) / 240 closed ( +1) / 484 total ( +5) New / Reopened Patches ______________________
1
3638
by: chriswilliams | last post by:
This code prints output in rows like this: ****** ****** ****** How to make print in blocks like this? ***** ***** ****** ***** ***** ****** ***** ***** ***** start= int (raw_input("StartTable?"))
2
2094
by: necron99 | last post by:
import RuntimeEnvironment as renv import os, sys import win32com.client import getpass OMI = win32com.client.Dispatch("MOVEitAPI.clientObj") OMI.Host = system
0
7542
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
8060
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
0
7903
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
1
5452
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
5170
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3593
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3573
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1156
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
863
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.