469,906 Members | 2,180 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,906 developers. It's quick & easy.

printing something without a newline OR a space after it?

Very very simple problem here, can't find out how to do it...

I want to print something without a new line after it, so I can later output
something right after it on the same line.

If I do:

print "stuff here",
print "more"

... it doesn't output a newline, but it does output a space:

stuff here, more

... whereas I want no newline and no space:
stuff here,more

How is this done?

thanks
alex

Jul 18 '05 #1
4 2061
Alex Hunsley wrote:
.. whereas I want no newline and no space:
stuff here,more

How is this done?


sys.stdout.write('foo')

--
Ciao,
Matteo
Jul 18 '05 #2
Matteo Dell'Amico wrote:
Alex Hunsley wrote:
.. whereas I want no newline and no space:
stuff here,more

How is this done?

sys.stdout.write('foo')


thankyou!

alex

Jul 18 '05 #3
import sys
sys.stdout.write( 'stuff here' )
sys.stdout.write( 'more' )

On Thu, Jun 03, 2004 at 02:23:01PM +0100, Alex Hunsley wrote:
Very very simple problem here, can't find out how to do it...

I want to print something without a new line after it, so I can later
output something right after it on the same line.

If I do:

print "stuff here",
print "more"

.. it doesn't output a newline, but it does output a space:

stuff here, more

.. whereas I want no newline and no space:
stuff here,more

How is this done?

thanks
alex


Jul 18 '05 #4
Alex Hunsley <la**@tardis.ed.ac.molar.uk> writes:
Very very simple problem here, can't find out how to do it...

I want to print something without a new line after it, so I can later
output something right after it on the same line.

If I do:

print "stuff here",
print "more"

.. it doesn't output a newline, but it does output a space:

stuff here, more

.. whereas I want no newline and no space:
stuff here,more

How is this done?

thanks
alex

Just "write" to your file. For stdout (equiv of print), you can use:

def msg(txt):
sys.stdout.write(txt)
sys.stdout.flush() #to see results immediately
Thus:
msg('stuff here,')
msg('more\n')

If you don't care about flushing, try:
out=sys.stdout.write
out('stuff here,')
out('more\n')

--
ha************@boeing.com
6-6M21 BCA CompArch Design Engineering
Phone: (425) 342-0007
Jul 18 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

11 posts views Thread by | last post: by
3 posts views Thread by Daniel Pryde | last post: by
30 posts views Thread by Martin Bless | last post: by
4 posts views Thread by Christoph Haas | last post: by
10 posts views Thread by Jeff B. | last post: by
7 posts views Thread by DazedAndConfused | last post: by
4 posts views Thread by beertje | last post: by
1 post views Thread by Waqarahmed | last post: by
reply views Thread by Salome Sato | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.