On Thu, 5 Jun 2008 08:50:32 pm Paul Moore wrote:
> On 05/06/2008, Steven D'Aprano <[EMAIL PROTECTED]> wrote:
> > Yes, I don't particularly see the advantage of writing:
> >
> > "spam %s spam" % (value,)
> >
> > over
> >
> > "spam %s spam" % value
> >
> > Why require the first version?
>
> Because the second breaks if value is a tuple:

That's a good reason for not using the second form if value is an 
arbitrary object that could be any type at all. But how often does that 
happen in real code? It's rare that the right hand argument can be any 
arbitrary type.

I've looked at my code, and there's not one occasion that I've needed to 
write "foo %s" % (obj,) to guard against obj unexpectedly being a 
tuple. If obj was a tuple, it would fail long before it reached the 
string expression. Of course, your mileage may vary.

As I see it, your argument is one for consistency: since *sometimes* you 
need to wrap the right-hand argument in a tuple, then we should insist 
in *always* wrapping it in a tuple. But of course you can do that right 
now:

>>> n = 1
>>> "number %d" % (n,)  # just in case n is a tuple
'number 1'


Just don't force me to do it.



-- 
Steven
_______________________________________________
Python-Dev mailing list
Python-Dev@python.org
http://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: 
http://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com

Reply via email to