Re: I can't inherit from "compiled" classes ?



En Sun, 29 Apr 2007 17:27:59 -0300, Maxim Veksler <hq4ever@xxxxxxxxx> escribió:

On 4/29/07, Marc 'BlackJack' Rintsch <bj_666@xxxxxxx> 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
.



Relevant Pages

  • Re: Class Variable Inheritance
    ... from most specific to least specific scope. ... If you actually assigned c1.mastervar, rather than modifying the dict, ... I strongly recommend a read of the book "Learning Python" if you want to ... classes, inheritance, and namespaces work. ...
    (comp.lang.python)
  • Re: New to Python: my impression v. Perl/Ruby
    ... After years and years of Perl use, I evaluated Ruby ... > and Python and have adopted Python. ... the socket module docs for the default timeout setting. ... Yes, that's a substantive difference in design, I agree ...
    (comp.lang.python)
  • Re: killing thread after timeout
    ... >> I am going to write python script which will read python>> command from socket, run it and return some values back to>> socket. ... The child processes can acceptincomming connections on its copy of the socket. ... and pipe the data to and from worker processes. ...
    (comp.lang.python)
  • Re: Sockets on Windows and Mac
    ... > I am new to Python and have been writing some socket based programmes ... > on Windows, however I am unable to get them to work ... > on Mac. ...
    (comp.lang.python)
  • Re: What are modules really for?
    ... > One thing I find weird about python is the idea of a module. ... In Java, every ... packages were a later addition to the language. ... Perhaps you are relying too much on inheritance, ...
    (comp.lang.python)