Extending Python

A module is created with the new functions via:

static PyMethodDef newMethods[] =
    {
    {"encrypt", encrypt, METH_VARARGS,
     "Returns an encrypted version of a string."},
    {"helloworld", helloworld, METH_VARARGS,
     "Prints 'Hello, world!'."},
    {NULL, NULL, 0, NULL}
    };

Py_InitModule("mymodule", newMethods);

Python code that is subsequently executed via an embedded interpreter (PyRun_*) can then do:

    import mymodule

    cryptText = mymodule.encrypt('A secret message')
    
    mymodule.helloworld()

next