views:

55

answers:

1

How would one expose "static" variables like this

class MyClass:
    X = 1
    Y = 2

via the C API? The only variable on the PyTypeObject that looks like it would work is tp_members, but I see no flag in the PyMemberDef to indicate that the member should be per-class, not per-instance.

For a bit more clarification, since it may change the answer, I'm trying to expose a C enum to Python such that the enumeration

enum MyFlags {
    Alpha = 0,
    Beta = 1
};

Can be accessed in Python as:

module.MyFlags.Alpha
module.MyFlags.Beta
+1  A: 

Just put them in the type's tp_dict e.g. with PyDict_SetItemString.

Alex Martelli
Excellent! That's what I was looking for. (You'll excuse me if I take a moment to test it out before marking this as answered.)
Toji
Works as advertised. :) Thanks again.
Toji