Home How to use an parent instance to replace child object's parent in python
Reply: 0

How to use an parent instance to replace child object's parent in python

MJ Chen
1#
MJ Chen Published in 2018-01-12 17:49:52Z

Here is my code:

import socket
import select
class My_socket(socket.socket):
    def __init__(self, soc = None):
        if soc == None:
            socket.socket.__init__(self, socket.AF_INET, socket.SOCK_STREAM)
            ....
        else:
            # how to use soc to initialize or replace parent part

....
rs, ws, es = select.select([my_socket_instance],[],[])
....

I want to create a my_socket class which has more functions, and when u pass no argument to its constructor, it will initialize its parent part automatically, but when u pass a socket instance as argument, it uses it as its parent so that my_socket can still work fine like just a socket ( for instance as an input of select function)

More specifically I met this problem when I get the (conn, addr) as a return of socket.accept(), and conn is socket type, I want to turn it to my_socket type, how to achieve that

thanks

You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.306049 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO