<div class="gmail_quote">On Wed, Nov 16, 2011 at 10:09 AM, Steven D'Aprano <span dir="ltr"><<a href="mailto:steve@pearwood.info">steve@pearwood.info</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">
<div class="im">Wayne Werner wrote:<br><snip></div><div class="im">
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
In old style formatting, you use a string with format specifiers (%s, %d,<br>
etc.) followed by a tuple of arguments. Here, the lengths have to match<br>
exactly - if you have one specifier then you must have a 1-element tuple.<br>
</blockquote>
<br></div>
That's actually wrong. If you have one specifier, you must have one object of any sort *except* a tuple.</blockquote><div><br></div><div>I think you misunderstood - I said a 1-element tuple - e.g. (3,)</div><div> </div>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;"><span style="background-color: transparent; "> </span></blockquote><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">
>>> "%s" % 42 # One object not a tuple.<br>
'42'<br>
<br>
But if you have a tuple, the % formatting will try to use each element in the tuple separately:<br>
<br>
>>> "%s" % (23, 42) # One object which is a tuple<br></blockquote><div><br></div><div>As above, that's a two-element tuple. It was explained to me once that in this case:</div><div><br></div><div>
"%s" % 42</div><div><br></div><div>That since python expects to see a single-element tuple it treats it as or converts 42 to a single element tuple.</div><div><br></div><div>I suppose I could have called it a tuple of length 1 instead.</div>
<div><br></div><div>Sorry for the mistunderstanding,</div><div>Wayne</div></div>