print and trailing white space

M

Maxime Biais

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()
 
P

Peter Hansen

Maxime said:
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
 
M

Maxime Biais

Thu, 18 Sep 2003 17:33:41 -0400
Peter Hansen said:
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.
 
P

Peter Otten

Maxime said:
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()
.... 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)
....x>>>

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

Peter
 
M

M-a-S

Thank you for a great example anyway!
M-a-S

Peter Otten said:
... 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)
...
x>>>

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

Peter
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,535
Members
45,007
Latest member
obedient dusk

Latest Threads

Top