[Python-Dev] Type/class differences (Re: Sets: elt in dict, lst.include)

Neil Schemenauer nas@arctrix.com
Mon, 5 Feb 2001 11:04:22 -0800


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


> >     PyObject {
> >         int ob_refcnt;
> >         PyClass ob_class;
> 
> (plus type-specific fields I suppose)

Yes, the instance attributes.  In this scheme all objects are
instances of some class.

> Yeah...  Like you should be able to ask for ListType.append and get an
> unbound built-in method back, which can be applied to a list:
> 
>     ListType.append([], 1) === [].append(1)


Right.  My changes on the weekend where quite close to making
this work.

  Neil