[Tutor] What does "TypeError: 'int' object is not iterable" mean?

Richard D. Moores rdmoores at gmail.com
Sat Oct 23 14:09:44 CEST 2010

On Sat, Oct 23, 2010 at 03:43, Dave Angel <davea at ieee.org> wrote:
> On 2:59 PM, Richard D. Moores wrote:
>> It's great to have you chime in, Steven. I do wish you would stop
>> pulling your punches, however. ;)
>> On Fri, Oct 22, 2010 at 17:23, Steven D'Aprano<steve at pearwood.info>
>>  wrote:

>>> float2n_decimals(x, 3)
>>> is better written in place as:
>>> "%.*f" % (3, x)
>>> There's no need for a function for something so simple.
>> Yes, but I needed one for ("%%.%sf" % n) % floatt .
>> <snip>
> Sometimes Steven's style can be a bit caustic, but there's almost always a
> few important nuggets.

Absolutely there are! And I have no problem with his style. I just
couldn't hold back what I intended to be a gentle jab of sarcasm.
Dangerous in email--especially an email list.

>  In this case, you missed the one that your
> formatting is unnecessarily complicated, at least if you have a recent
> enough Python version.
> In particular,
>     "%.*f" % (n, myfloat)
> will convert myfloat to a string, and use n as the precision, just as your
> more complex expression.  The asterisk is the magic character, that says use
> n as the precision field.

Thanks for that. Actually, I missed that nugget because Steven had it as

float2n_decimals(x, 3)

is better written in place as:

"%.*f" % (3, x)

I didn't pick up on it because I wanted to use 'n' where he had the
'3'. I didn't realize that your  "%.*f" % (n, myfloat) was possible.

> This syntax was available at least in 2.3, so unless you need to use an
> older version, there's not much need for the two-stage template system.

Thanks, Dave,


More information about the Tutor mailing list