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 4 3487
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
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
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_softspace, _set_softspace)
.... def write(self, s):
.... sys.stdout.write(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
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_softspace, _set_softspace) ... def write(self, s): ... sys.stdout.write(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 This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
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'...
|
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:...
|
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"?>...
|
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,...
|
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:...
|
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
...
|
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...
|
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...
|
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)$...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
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...
|
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,...
|
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...
|
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...
|
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...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
| |