As I mentioned in the last post, I’ve recently added reduce(), map() and filter() to functional. Since these mimic the semantics of the original Python built-ins, and since I wanted a sane version of map() at the same time, I decided to move reduce() and co. into a separate backwards compatibility-focused submodule, functional.bwcompat.

Now, this wasn’t a problem for the pure Python version of functional — you just add a new bwcompat.py in the functional/ directory. However, the C version turned out to be a bit trickier.

Most extension modules are just that — modules — meaning that there’s a foomodule.c file that creates an importable foo module. There’s little, if any, intentional support for creating packages at the C level. The popular way, as some googling turned up, is to create the root module, then manually add the submodules using PyModule_AddObject(). This works, but it means that all your submodules are imported as soon as you import the root namespace. It’s not a big deal, but it’s not ideal, either (for more background, see this python-dev thread.).

If you find yourself in the same situation, initfunctional() in functionalmodule.c should make a pretty good guide. A more stripped-down version can be found in this python-list post from Alex Martelli

.