steve+comp.lang.pyt...@pearwood.info wrote:

> Unfortunately, while that gets rid of the newline, it also leaves 
spaces
> between items:
> 
>>>> def example():
> ...     print 1,
> ...     print 2,
> ...     print 3
> ...
>>>> example()
> 1 2 3
> 
> Here's the Python 3 version:
> 
>>>> def example():
> ...     print(1, sep='', end='')
> ...     print(2, sep='', end='')
> ...     print(3, sep='')
> ...
>>>> example()
> 123
> 
> 
> To get the same result in Python 2, you have to use sys.stdout.write
().
> 

That isn't entirely true: you could set the `softspace` attribute on 
sys.stdout, but that is even messier.

>>> def foo():
...     print 1,
...     sys.stdout.softspace=0
...     print 2,
...     sys.stdout.softspace=0
...     print 3
...
>>> foo()
123

-- 
Duncan Booth http://kupuguy.blogspot.com
-- 
http://mail.python.org/mailman/listinfo/python-list

Reply via email to