[Tutor] Inherit from int?

John Fouhy john at fouhy.net
Sun May 13 02:11:34 CEST 2007


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.


More information about the Tutor mailing list