In a dynamic language, why % operator asks user for type info?

Asun Friere afriere at
Wed Jul 18 04:25:39 CEST 2007

On Jul 17, 5:38 pm, Duncan Booth < at invalid.invalid> wrote:

> indeed anything which has an __int__ method may be
> passed to the %d formatter:

Anything?! Sorry to be persnickety here, but what about this:

class C :
  def __int__ (self) : pass

'%d' % C()

or this:

def foo (val) : return val
foo.__int__ = lambda x=42 : int(x)

'%d' % foo('spam')

OK, they can be passed ...

More information about the Python-list mailing list