String formatting strangeness

Fredrik Lundh fredrik at pythonware.com
Fri May 13 09:42:51 EDT 2005


dark.ryder at gmail.com wrote:

> <type 'int'> <type 'str'> <type 'int'> <type 'int'>
> Traceback (most recent call last):
>   File "X:\Music (FLAC)\Post-process new rips.py", line 50, in ?
>     print "\t\t\t<section number=\"%i\" title=\"%s\"
> length=\"%i:%i\"/>\n" % [number, name, seconds // 60, seconds % 60]
> TypeError: int argument required
>
> Wait, what?  The first line clearly identifies that the the first,
> third, and fourth elements are all integers, yet the error says that
> *lack* of integers is the problem.  If I change all "%i"s to "%d", I
> get the same problem, and changing to "%s" (hey, it was worth a shot)
> gives "TypeError: not enough arguments for format string" instead.
> Huh?  I see four placeholders and a four-element tuple.

[number, name, seconds // 60, seconds % 60] is not a tuple.

(number, name, seconds // 60, seconds % 60) is a tuple.

</F>






More information about the Python-list mailing list