printing something without a newline OR a space after it?

A

Alex Hunsley

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
 
H

Harry George

Alex Hunsley said:
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')
 

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

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,537
Members
45,022
Latest member
MaybelleMa

Latest Threads

Top