Let's say you're making a nice class and you want to expose some constant property of the class so that code that uses your class will know, for example, what kind of data type the class deals in. In Java or C++ you create a constant static member and you're set. In python you do the same thing, except these variables are called class variables. But how do you do this when you're defining a Python class in C or C++?
The answer is probably totally obvious to anyone who uses python a lot, but it took me more than 15 minutes to find the answer, so it goes here: you put it in the class dictionary. With normal python objects both the instance and the class have a dictionary that contains the attributes of the instance. The instance dictionary takes precedence, so if you define a class variable and then subsequently assign some value to that variable for an instance, it gets stored in the instance dictionary, and that's the value you get if you access that attribute in the future. Types defined in C extension modules generally don't have instance dictionaries, so anything you put in the type dictionary winds up being read-only.
Here's the line I used (in the initialization function) to create the class variable _dtype and assign it the numpy dtype associated with the data the class processes.
PcmfileType.tp_dict = Py_BuildValue("{s:O}", "_dtype", (PyObject *)PyArray_DescrFromType(NPY_SHORT));