Pre-PEP: Refusing to guess in string formatting operations

Cherniavsky Biniamin cben at techunix.technion.ac.il
Mon Mar 17 05:15:46 EST 2003


In article <v6sk9tg375gke8 at news.supernews.com>, John Roth wrote:
>
>Your first proposal won't make the issue go away. I'm simply
>not that rigorous that I remember each and every time to wrap
>the right operand to '%' with a tuple.
>
You better be <wink>, or once in a while you get biten by it.  The whole point
of the first proposal was to provide something very easy to type instead of
wrapping in an ugly singleton tuple.

>Frankly, if there's going to be a fix, the one I'd rather see is a
>recognition that the programmer knew what he was doing, and if the '%'
>processor sees a tuple when there is only one request in the pattern string,
>then format it as a tuple if that's possible given the format code.
>
You mean like this:

>>> '[%s,%s]' % (1, 2)
'[1,2]'
>>> '[%s]' % (1, 2)
'[(1,2)]'
>>> '[%s]' % 1
'[1]'

Hmm, this is an interesting idea.  Would work well if it had been so from the
beginning.  Unfortunately, it'd be backward-incompatible currently, and it
leaves you with no unambigous syntax for the transition period.

>As far as the second proposal is concerned,
>I'd prefer a built-in rather than a string method, but either would
>do nicely. Either one has the additional benefit that it fixes
>the line continuation problem with print and the format operation
>rather cleanly.
>
>First proposal: -1
>Second proposal: + 1/2
>

-- 
Beni Cherniavsky <cben at tx.technion.ac.il>




More information about the Python-list mailing list