socket module

Skip Montanaro skip at
Mon Jul 9 16:43:39 CEST 2001

    Martin> Is there ANY way to use the socket module from a Python module
    Martin> written in C?

Sure.  Check the C API manual:

especially the sections on importing modules and the object protocol section
(for calling callable objects).

Basically, you'll do just what you'd do from Python:

    import socket
    sock = socket.socket(...)

Something vaguely like:

    PyObject *sockmodule, *sockfunc, *socket;
    sockmodule = PyImport_Import("socket");
    sockfunc = PyDict_GetItemString(PyModule_GetDict(sockmodule), "socket");
    PyCall_Object(sockfunc, ...);

Skip Montanaro (skip at

More information about the Python-list mailing list