473,804 Members | 2,122 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

print and trailing white space

Hello,

I know how to print a string without the trailing newline with a coma
like :

print "hello word",

but this example add a white space after the string :(

Do you know how to avoid this white space without using write()

--
Maxime Biais
Jul 18 '05 #1
4 3503
Maxime Biais wrote:

Hello,

I know how to print a string without the trailing newline with a coma
like :

print "hello word",

but this example add a white space after the string :(

Do you know how to avoid this white space without using write()


What's wrong with write() ? Print is merely provided for convenience.
When it's not doing what you want, you are supposed to use write(),
not come up with weird hacks for print.

-Peter
Jul 18 '05 #2
Thu, 18 Sep 2003 17:33:41 -0400
Peter Hansen <pe***@engcorp. com> wrote:
What's wrong with write() ? Print is merely provided for convenience.
When it's not doing what you want, you are supposed to use write(),
not come up with weird hacks for print.


ok sorry, I believed write was not buffered. I just read the library
reference part on write() and see I was wrong.

--
Maxime Biais
Jul 18 '05 #3
Maxime Biais wrote:
I know how to print a string without the trailing newline with a coma
like :

print "hello word",

but this example add a white space after the string :(

Do you know how to avoid this white space without using write()

class Out(object): .... def _set_softspace( self, value):
.... pass
.... def _get_softspace( self):
.... return False
.... softspace = property(_get_s oftspace, _set_softspace)
.... def write(self, s):
.... sys.stdout.writ e(s)
.... out = Out()
print >> out, "a", "b", "c" abc print >> out, "x",

x>>>

It's possible, but I'd rather go with write().
And, please, never ever substitute sys.stdout with a similar object.

Peter

Jul 18 '05 #4
Thank you for a great example anyway!
M-a-S

"Peter Otten" <__*******@web. de> wrote in message news:bk******** *****@news.t-online.com...
class Out(object): ... def _set_softspace( self, value):
... pass
... def _get_softspace( self):
... return False
... softspace = property(_get_s oftspace, _set_softspace)
... def write(self, s):
... sys.stdout.writ e(s)
... out = Out()
print >> out, "a", "b", "c" abc print >> out, "x",

x>>>

It's possible, but I'd rather go with write().
And, please, never ever substitute sys.stdout with a similar object.

Peter

Jul 18 '05 #5

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

Similar topics

30
4181
by: Martin Bless | last post by:
Why can't we have an additional 'print' statement, that behaves exactly like 'print' but doesn't insert that damn blank between two arguments? Could be called 'printn' or 'prin1' or 'prinn' anything similar you like. Would make my life so much easier. Often I start with a nice and short print statement, then there happen to be more arguments and neat formatting becomes more important and as a result I find myself
14
2921
by: Marcin Ciura | last post by:
Here is a pre-PEP about print that I wrote recently. Please let me know what is the community's opinion on it. Cheers, Marcin PEP: XXX Title: Print Without Intervening Space Version: $Revision: 0.0 $
0
1450
by: Leo | last post by:
Can the value of the union datatype contain leading/trailing white space if it's not allowed by the member datatypes? For example, in the following example: t1.xsd: <?xml version="1.0"?> <xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema" targetNamespace="http://www.t1.org" xmlns="http://www.t1.org" elementFormDefault="qualified">
2
5131
by: jamesthiele.usenet | last post by:
I recently ran into the issue with 'print' were, as it says on the web page called "Python Gotchas" (http://www.ferg.org/projects/python_gotchas.html): The Python Language Reference Manual says, about the print statement, A "\n" character is written at the end, unless the print statement ends with a comma. What it doesn't say is that if the print statement does end with a
4
3226
by: ucfcpegirl06 | last post by:
Hi, I need help getting rid of trailing white spaces. I am searching a file for various data (not important) and retrieving it. I output the data if found to a file. An example would be: HD='Three blind mice ' My output would consist of: Three Blind Mice (w/ all the white space behind being printed until the quote mark is reached) I don't the white space after the text to be printed.
0
1837
by: bearophileHUGS | last post by:
There is/was a long discussion about the replacement for print in Python 3.0 (I don't know if this discussion is finished): http://mail.python.org/pipermail/python-dev/2005-September/055968.html There is also a wiki page that collects the ideas: http://wiki.python.org/moin/PrintAsFunction There is the will to keep the printing operation very simple for the most common situation, but at the same time to make it flexible (optional no...
2
6680
by: shagy | last post by:
Hi, I'm having a problem with a <select><option> which has white space in values... When I post the data I only get the first word (up to the white space). "Testing white space" becomes "Testing" after posting code... <select name="descr" id="descr">
17
11888
by: tommy | last post by:
Hi all, I' m adding strings to some fields in my table via Access. The strings sometimes have trailing spaces and I really need to have it that way, but Access truncates trailing spaces. How can I force Access not to truncate?! Thanx, /Toommy
5
1746
by: tim | last post by:
I am new to Regular Expressions and need some assistance with my Zip Code field validator. I am currently using the following regex to validate a zip code: ^(\d{5}(( |-)\d{4})?)|(\d( |-)\d\d)$ I would like to account for any number of leading and trailing whitespace characters but am not sure how to do so. Thanks in advance for your help.
0
9716
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
9595
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
10354
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
10101
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
7643
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
5536
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
5675
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4314
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
3837
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.