Accessing Python variables in an extension module
Hrvoje Niksic
hniksic at xemacs.org
Mon Jul 16 14:56:26 EDT 2007
MD <manasd at gmail.com> writes:
> 2) Is there anyway to find the type of the object in C using something
> like a switch statement? I was looking for something like this
> switch type(object) {
> STRING: "This is a string object";
> break;
> INTEGER: "This is an integer object";
> break;
> BOOLEAN: "This is a boolean object";
> .........
> .........
> }
Not switch, but the closest you'll get is:
if (object->ob_type == PyString_Type) {
... string
}
else if (object->ob_type == PyInt_Type) {
... int
}
else if (object->ob_type == PyBool_Type) {
... bool
}
> I don't want to run all the C Py***_Check functions on the object.
Py*_Check are not expensive if the object really is of the target
type. They are necessary to support subtyping correctly.
More information about the Python-list
mailing list