[Tutor] TypeError: not enough arguments for format string

John Fouhy john at fouhy.net
Wed Jul 2 06:49:19 CEST 2008

On 02/07/2008, Christopher Spears <cspears2002 at yahoo.com> wrote:
>   File "point.py", line 13, in __str__
>     point_str = "(%f,%f)" % self.x, self.y
>  TypeError: not enough arguments for format string
>  Does anyone know what is wrong?  I'm sure it is something obvious, but I can't see it.

Hi Christopher,

Here's the short answer: You need to put brackets around "self.x, self.y"
i.e.     point_str = "(%f,%f)" % (self.x, self.y)

The long answer: Python interprets the statement "point_str =
"(%f,%f)" % self.x, self.y" as "point_str = ("(%f,%f)" % self.x),
self.y".  There are two "%f" expressions in the string, but you only
supplied one argument, self.x.  Thus python tells you that there
aren't enough arguments.  To deal with this, you need to supply the
arguments as a tuple.


More information about the Tutor mailing list