Why can't I override this method in python? -
i'm trying override python class (first time doing this), , can't seem override method. when run this, recv method doesn't run. runs superclasses's method instead. doing wrong here? (this python 2.7 way.)
import socket class persistentsocket(socket.socket): def recv(self, count): print("test") return super(self.__class__, self).recv(count) if __name__ == '__main__': s = persistentsocket(socket.af_inet, socket.sock_stream) s.connect(('localhost', 2300)) print(s.recv(1)
the socket type (officially socket.sockettype, though socket.socket happens same object) makes strange choice of implementing recv , few other methods instance attributes, rather normal methods in class dict. in socket.sockettype.__init__, sets self.recv instance attribute overrides recv method tried define.
Comments
Post a Comment