Please hear my plea: print without softspace

Mel Wilson mwilson at the-wire.com
Sat Feb 28 16:40:30 CET 2004


In article <9nrc43idsjh1.7af9ozuv2nc7$.dlg at 40tude.net>,
Valentino Volonghi aka Dialtone <dialton3.NOSPAM_ at virgilio.it> wrote:
>In data Sat, 28 Feb 2004 12:01:40 +0000 (UTC), Carmine Noviello ha
>scritto:
>
>> def pprint(*args):
>>     txt = ""
>>     for a in args:
>>        txt += str(a)
>>     print txt
>>
>> Is it ok?
>
>I would use this instead:
>
>def pprint(*args):
>    txt = []
>    for a in args:
>        txt.append(a)
>    print ''.join(txt)
>
>which is a lot faster :)

Sorry.

Python 2.3 (#46, Jul 29 2003, 18:54:32) [MSC v.1200 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> def pprint(*args):
...     txt = []
...     for a in args:
...         txt.append(a)
...     print ''.join(txt)
...
>>> pprint (1,2,3)
Traceback (most recent call last):
  File "<stdin>", line 1, in ?
  File "<stdin>", line 5, in pprint
TypeError: sequence item 0: expected string, int found



def pprint (*args):
    print ''.join ([str(x) for x in args])



        Regards.        Mel.



More information about the Python-list mailing list