I can't inherit from "compiled" classes ?

Gabriel Genellina gagsl-py2 at yahoo.com.ar
Sun Apr 29 19:38:22 EDT 2007


En Sun, 29 Apr 2007 17:27:59 -0300, Maxim Veksler <hq4ever at gmail.com>  
escribió:

> On 4/29/07, Marc 'BlackJack' Rintsch <bj_666 at gmx.net> wrote:
>>
> """
> from socket import socket
> import select
>
> class PollingSocket(socket):
>    pass
> """
>
>> `select.select()` is a function:
>
> I understand what you are saying, and at the same time don't
> understand why it doesn't work. Isn't "everything an object" in
> python? And if something is an object does it not implies it's an
> instance of some class?

I'm not sure if your last statement is true now, and certainly it was not  
true before Python 2.2; there were objects that were not class instances  
(numbers, functions, by example). Maybe some objects still remain that are  
not instances of any class.
Anyway, "an object" and "a class" are not the same thing, and you can't  
use an arbitrary object when you actually need a class.

> Does this mean I can't somehow make this work: """class
> PollingSocket(socket.socket, select):""" ?

Those things inside () are called "base classes"; this is "class"  
inheritance; you create a new "class" inheriting from existing ones. That  
is, you cant inherit from select, because select is a function, not a  
class.

-- 
Gabriel Genellina



More information about the Python-list mailing list