Asun Friere <[EMAIL PROTECTED]> wrote:

> On Jul 17, 5:38 pm, Duncan Booth <[EMAIL PROTECTED]> 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()
> 
__int__ is a reserved method name so it is reasonable to assume that any 
such method will act as documented: "Should return a value of the 
appropriate type." If you choose to ignore the documentation then expect 
exceptions to be thrown.

> or this:
> 
> def foo (val) : return val
> foo.__int__ = lambda x=42 : int(x)
> 
> '%d' % foo('spam')
> 

I don't see any methods named '__int__' there, just a function assigned to 
an attribute. (Yes, I know that isn't the problem, assigning a function to 
an __int__ attribute works for other types, but if you can be silly so can 
I.)
-- 
http://mail.python.org/mailman/listinfo/python-list

Reply via email to