A trivial question about print
Brad Bollenbach
bbollenbach at shaw.ca
Thu Apr 11 21:37:59 EDT 2002
In article <3CB58302.5090200 at mxm.dk>, Max M wrote:
> btw: it would be nice if join() had a switch so that it would
> automatically do a str() on each object it joins.
>
> like::
>
> >>> print ','.join(range(5), toStr=1)
> 0,1,2,3,4
>
> I keep having to do this repeatedly in my code when formatting output.
>
> Perhaps join() should even do this as the default, as it makes the most
> sense in the join() context.
>
> like::
>
> def newJoin(self, items):
> return self.join([str(i) for i in items])
>
> Is there any case where it isn't applicable at all?
There's lots of places where it's not applicable:
>>> amounts = [1.234, 5.281, 45.23421]
>>> ','.join(["%.2f" % x for x in amounts])
'1.23,5.28,45.23'
or whatever. The point is, the possibilities are limited only by your
imagination.
HTH,
Brad Bollenbach
More information about the Python-list
mailing list