473,657 Members | 2,478 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

how do i keep python from printing a newline when it exits theprogram?


Here is a simple script:
#!/usr/bin/python

print "No newline, please.",
# End of script

When the program runs, python is still printing a newline when the
program exits. How does one keep python from doing so?

Thanks!

Jul 18 '05 #1
2 1549
xegfault wrote:
print "No newline, please.",
# End of script

When the program runs, python is still printing a newline when the
program exits. How does one keep python from doing so?


Use sys.stdout.writ e() instead of print or clear the softspace flag

sys.stdout.soft space = False

after the print statement. Google 'site:mail.pyth on.org exit newline' for
some background.

Peter

Jul 18 '05 #2
"xegfault" <ss*****@questi a.com> writes:
Here is a simple script:
#!/usr/bin/python

print "No newline, please.",
# End of script

When the program runs, python is still printing a newline when the
program exits. How does one keep python from doing so?


class softspaceLess(o bject):
"""
import sys
print "a", "b", " ", "d" a b d print >>softspaceLess (sys.stdout), "a", "b", " ", "d"

ab d
"""
def __init__(self, file=sys.stdout ):
self.__dict__['_file'] = file
file.softspace = False
def __getattr__(sel f,a):
if a == 'softspace': return False
return getattr(self._f ile,a)
def __setattr__(sel f,a,v):
if a=='softspace': return
setattr(self._f ile,a,v)
'as
Jul 18 '05 #3

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

Similar topics

699
33866
by: mike420 | last post by:
I think everyone who used Python will agree that its syntax is the best thing going for it. It is very readable and easy for everyone to learn. But, Python does not a have very good macro capabilities, unfortunately. I'd like to know if it may be possible to add a powerful macro system to Python, while keeping its amazing syntax, and if it could be possible to add Pythonistic syntax to Lisp or Scheme, while keeping all of the...
7
3114
by: David Mertz | last post by:
In the endless Lisp/macro threads, Alex Martelli mentioned something a bit interesting about screen-reading applications. Specifically, he expressed reservations about whether Python would be a good language for visually impaired or blind programmers. The concern, I think, is that pronouncing 'space-space-space-space-space-space-space-space' isn't all that easy to follow if spoken with every line. Even a reduced form like...
2
2599
by: Manlio Perillo | last post by:
Hi. This post follows "does python have useless destructors". I'm not an expert, so I hope what I will write is meaningfull and clear. Actually in Python there is no possibility to write code that follows C++ RAII pattern. Of course Python objects are not statics like in C++, but in C++ the auto_ptr class is used for enforcing this pattern for dynamical
1
1402
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 != "":
2
2656
by: S. Staats | last post by:
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.
5
4076
by: Kit | last post by:
Hey there, and thanks for reading a newbie post. I have a lex assignment in which we are supposed to grab strings from a C source file, and print them out to the screen, with escaped characters "converted". Here's part of the assignment text: ---------------------------------------------------------------- Example: main() { char *s = "This is string one";
7
96293
by: teachtiro | last post by:
Hi, 'C' says \ is the escape character to be used when characters are to be interpreted in an uncommon sense, e.g. \t usage in printf(), but for printing % through printf(), i have read that %% should be used. Wouldn't it have been better (from design perspective) if the same escape character had been used in this case too. Forgive me for posting without verfying things with any standard compiler, i don't have the means for now.
1
2079
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
1371
by: Gary Josack | last post by:
Gary Herron wrote: Also os.popen is deprecated. You should probably learn subprocess. Thanks, Gary M. Josack
0
8420
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
8842
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8740
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...
1
8516
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8617
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
6176
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
4173
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...
1
2743
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
2
1970
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.