verifying type of socket object?

Peter Wang pzw1 at cor-no-spam-nell.edu
Thu Nov 1 12:51:05 EST 2001


in my code, i'd like to verify that i get passed a socket object.
however, i'm having some trouble figuring out what exactly represents
the "socket type".  the main problem is that socket.socket() doesn't
return instances of socket.SocketType:

>>> x = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
>>> socket.SocketType
<type 'socket'>
>>> isinstance(x, socket.SocketType)
0
>>> x
<socket._socketobject instance at 011232A4>
>>> isinstance(x, socket._socketobject)
1
>>> 

my question is, how can i achieve the effect of the last isinstance()
call without having to touch an underscored member of the socket
module?

TIA,
peter




More information about the Python-list mailing list