Again: Please hear my plea: print without softspace

David MacQuigg dmq at gain.com
Wed Mar 3 13:33:36 EST 2004


On Wed, 03 Mar 2004 10:32:34 GMT, m.bless at gmx.de (Martin Bless) wrote:

>["Rainer Deyke" <rainerd at eldwood.com>]
>
>>but only because 'sys.stdout.write' is too long to type all
>>the time, and never with more than one argument.

If the only remaining issue is multiple arguments:

>>> import sys
>>> def wrt(*args):
	for arg in args:
		sys.stdout.write(arg)

>>> wrt('abc','xyz\n','abc',1,2,3)
abcxyz
abc123
>>> 

-- Dave


>Yes, I feel it's a pity that the standard write method of file objects
>doesn't take multiple arguments. Would take some of the pressure.
>
>One thing I can do since Python-2.2 is to inherit from 'file' and add
>for example a 'writem' (write many, write multiple) method. This does
>work.
>
>Unfortunately it seems I can't add that 'writem' method to sys.stdout,
>as the following shows.
>
>Anybody any ideas?
>
>
>#!/usr/bin/env python
># -*- coding: iso-8859-1 -*-
>"""Test file object."""
>
>__author__ = "Martin Bless, 2004-03-03"
>
>if 1 and "this does work":
>    class MyFile(file):
>
>        def writem(self,*args):
>            "Method to write many arguments."
>            for arg in args:
>                self.write(str(arg))
>
>    f2name = 'xxxtempfile'
>    f2 = MyFile(f2name,'w')
>    f2.writem(1,2,3,4)
>    f2.close()





More information about the Python-list mailing list