You could use the ''.join method. e.g.
# print 'foo', 'bar', 'baz' separated by spaces
print 'foo', 'bar', 'baz'
# print separated by commas
print ', '.join(['foo', 'bar', 'baz'])
EDIT:
Ok, I misunderstood the purpose of OUTPUT_RECORD_SEPARATOR
, so ''.join is not what you want.
print 'foo'
is equivalent to sys.stdout.write('foo'+'\n')
, so you could roll your own print function:
def myprint(*args, end='\n'):
sys.stdout.write(' '.join(args) + end)
Or go one step further with a factory function:
def make_printer(end):
def myprint(*args, end='\n'):
sys.stdout.write(' '.join(args) + end)
return myprint
# usage:
p = make_printer('#')
p('foo', 'bar', 'baz')
Finally, if you're daring, you could override sys.stdout:
sys.old_stdout = sys.stdout
class MyWrite(object):
def __init__(self, end='\n'):
self.end = end
def write(self, s):
sys.old_stdout.write(s.replace('\n', self.end))
This will cause print
statements to produce the alternative line ending. Usage:
sys.stdout = MyWrite('!\n')
print 'foo'
# prints: foo!
Note that you may need to override more than just write() – or at least provide redirects for things like MyWrite.flush() to sys.old_stdout.flush().