[Python-3000] String formating operations in python 3k

Barry Warsaw barry at python.org
Mon Apr 3 16:55:54 CEST 2006


On Mon, 2006-04-03 at 23:43 +1000, Nick Coghlan wrote:

> What do you think of a "format" builtin function that accepts the format as 
> the first argument (similar to printf).
> 
> The version on my harddrive permits positional arguments via $1, $2, etc, as 
> well as string formatting (by sticking the format code in square brackets 
> between the $ and the identifier). Keyword arguments still work, naturally.
> 
> And if you don't want formatting, you just leave out the square brackets.

I'm not totally sure I would need a builtin.  If I look at the two
sources of $-strings in an app like Mailman, I'll see 1) literal human
readable/translatable strings in the source code, 2) human entered
strings that come from a web form.

In the first case, all string formatting will funnel through one
bottleneck function, which will do the catalog lookup, frame variable
discovery, and substitution all in one fell swoop.  So there, the
builtin doesn't buy you much convenience.

In the second case, it's possible that it could help you a bit, but even
there, I don't think a builtin would buy you much clarity or simplicity.

I'm willing to believe that my uses are fairly narrow and that such a
builtin could be useful for other applications, but I don't see too much
of a benefit for the code I've written.

-Barry

-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 309 bytes
Desc: This is a digitally signed message part
Url : http://mail.python.org/pipermail/python-3000/attachments/20060403/dd6a5927/attachment.pgp 


More information about the Python-3000 mailing list