[Tutor] Inherit from int?

jim stockford jim at well.com
Sun May 13 02:32:20 CEST 2007


the problem is in the return.

if you append a print statement to the class function
such as
print "number is ",number   # (properly indented, of course)
you'll get 8



On May 12, 2007, at 5:11 PM, John Fouhy wrote:

> On 13/05/07, Marilyn Davis <marilyn at deliberate.com> wrote:
>> #!/usr/bin/env python
>> '''An Under10 class, just to fiddle with inheriting from int.'''
>>
>> class Under10(int):
>>
>>     def __init__(self, number):
>>         number %= 10
>>         int.__init__(self, number)
>
> Subclassing int and other types is a bit special.  Check out this
> page; it may help you:
> http://www.python.org/download/releases/2.2.3/descrintro/#__new__
>
> --
> John.
> _______________________________________________
> Tutor maillist  -  Tutor at python.org
> http://mail.python.org/mailman/listinfo/tutor
>



More information about the Tutor mailing list