String formatting (%)
A. Lloyd Flanagan
alloydflanagan at comcast.net
Fri Apr 30 09:51:39 EDT 2004
padhia at yahoo.com (P Adhia) wrote in message news:<3281a460.0404291301.3c3c647d at posting.google.com>...
> Another version of a more compact function would be,
>
> def commafy(s):
> return len(s) > 3 and "%s,%s" % (commafy(s[:-3]), s[-3:]) or s
>
> Note that this function accepts string representation of an integer
> (without checks of course).
>
> P Adhia
And it seeems to work beautifully. Thanks, that's a great improvement.
More information about the Python-list
mailing list