Again: Please hear my plea: print without softspace

David MacQuigg dmq at gain.com
Thu Mar 4 19:08:49 EST 2004


On Thu, 04 Mar 2004 22:43:41 +0000, Stephen Horne
<steve at ninereeds.fsnet.co.uk> wrote:

>def print (*args) :
>  sys.stdout.write (string.join ([str(i) for i in args], " ") + "\n")

Cool. But we can go one better. The join function requires that we
import the soon-to-be-deprecated ( I am told.) string module.  The
proper way ( I am told.) is to use the join *method*:

>>> def prnt(*args):
	sys.stdout.write(' '.join([str(i) for i in args]) + '\n')
>>> prnt(1,2,3)
1 2 3
>>> 

Actually, I think this is rather ugly. The string 'method' still looks
like a 'function'.  We really need a 'join' method that takes a list
of strings as its 'front-door' object and the 'joiner' as its optional
'side-door' input.  Then we could do like Ruby and say:

[str(i) for i in args].join(' ').append('\n')

For another good example of Ruby's advantage in sequential operations
on strings see http://userlinux.com/cgi-bin/wiki.pl?RubyPython

Incidentally, sys.stdout.write(i) *will* work on integers (at least in
Python 2.3.3 running in IDLE 1.0.2)  It doesn't work if I start Python
from a command line!!  Very strange.  I do run my examples before
posting.

-- Dave




More information about the Python-list mailing list