Please hear my plea: print without softspace

kosh kosh at aesaeion.com
Sat Feb 28 17:44:57 CET 2004


On Saturday 28 February 2004 07:32 am, Valentino Volonghi aka Dialtone 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 :)

why not?

def pprint(*args):
    print ''.join(args)

if you want it to be more robust you could do

def pprint(*args):
    print ''.join(map(str,args))

That would try and convert all the items to a string first before joining 
them.




More information about the Python-list mailing list