[Python-Dev] Type/class differences (Re: Sets: elt in dict, lst.include)
Guido van Rossum
guido@digicool.com
Mon, 05 Feb 2001 15:24:19 -0500
> On Mon, Feb 05, 2001 at 01:37:39PM -0500, Guido van Rossum wrote:
> > Now, can you do things like this:
> [example cut]
>
> No, it would have to be written like this:
>
> >>> from types import *
> >>> class MyInt(IntType): # add a method
> def add1(self): return self.value+1
>
> >>> i = MyInt(10)
> >>> i.add1()
> 11
> >>>
>
> Note the value attribute. The IntType.__init__ method is
> basicly:
>
> def __init__(self, value):
> self.value = value
So, "class MyInt(IntType)" acts as a sort-of automagical "UserInt"
class creation? (Analogous to UserList etc.) I'm not sure I like
that. Why do we have to have this?
--Guido van Rossum (home page: http://www.python.org/~guido/)