Subclassing int

G gggg.iiiii at gmail.com
Mon Jul 23 22:23:28 EDT 2007


Thanks a lot Matt and Steve. I replaced __int__ with __new__ and it worked


On 7/23/07, Matt McCredie <mccredie at gmail.com> wrote:
>
> Do you guys know why the if statement is not evaluated?
>
>
> For immutable types __new__ is called before __init__. There are some
> details here: http://docs.python.org/ref/customization.html. Also, it
> isn't really clear what you want to do if the value is set to None anyway.
> In your example you return None, but that simply won't work since you can't
> return anything from __init__. Perhaps your need could be met by a function
> instead:
>
> <code>
> def INT(x):
>     if x is None:
>         return None
>     else: return int(x)
> </code>
>
> -Matt
>
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20070723/3a8ba450/attachment.html>


More information about the Python-list mailing list