473,748 Members | 9,641 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 2662
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
2590
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 between those two lines to transform the image.
1
1405
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', 'r') flag=0 while not flag aLine = file.readline() if aLine != "":
13
3004
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 decide to try to run it under Win32. After installing the Numeric and Gnuplot modules, I only had...
12
2316
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 good spam- related tools written in Python, so I thought I might get away with it :-) Yes,...
20
7905
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
2084
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
3646
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
2104
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
8989
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8828
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 synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9367
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 captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9243
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 choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6795
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 instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6073
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 into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4599
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 the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4869
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3309
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

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.