printing something without a newline OR a space after it?

Discussion in 'Python' started by Alex Hunsley, Jun 3, 2004.

  1. Alex Hunsley

    Alex Hunsley Guest

    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?

    Alex Hunsley, Jun 3, 2004
    1. Advertisements

  2. Alex Hunsley

    Phil Frost Guest

    import sys
    sys.stdout.write( 'stuff here' )
    sys.stdout.write( 'more' )
    Phil Frost, Jun 3, 2004
    1. Advertisements

  3. sys.stdout.write('foo')
    Matteo Dell'Amico, Jun 3, 2004
  4. Alex Hunsley

    Alex Hunsley Guest


    Alex Hunsley, Jun 3, 2004
  5. Alex Hunsley

    Harry George Guest

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

    def msg(txt):
    sys.stdout.flush() #to see results immediately

    msg('stuff here,')

    If you don't care about flushing, try:
    out('stuff here,')
    Harry George, Jun 3, 2004
    1. Advertisements

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 (here). After that, you can post your question and our members will help you out.