Reputation: 675
I have reason to want to call int.__format__
directly. I tried the following
>>> object.__format__(1,'d')
But get an exception
TypeError: unsupported format string passed to int.__format__
What should the fmt_spec
be?
Upvotes: 1
Views: 371
Reputation: 363083
Well, you used object.__format__
not int.__format__
. Try one of these instead:
>>> int.__format__(1, 'd')
'1'
>>> (1).__format__('d')
'1'
The behaviour you're seeing with non-empty string passed to object.__format__
is documented:
Changed in version 3.4: The
__format__
method of object itself raises aTypeError
if passed any non-empty string.
Upvotes: 1