views:

19

answers:

1

I have a c function being called from python. Python gives the function an integer, but I would like to use it as another data type in C. I am currently using

PyArg_ParseTuple (args, "i", &value) and then manually doing a cast on value.

Is there a way to do this cast through PyArg?

A: 

Which data type are you trying to cast the argument to in C?

If you want an integer type, it looks like you might be able to get it by using a different format string in PyArg_ParseType(). For example, "b" converts a non-negative Python integer into an unsigned char.

unsigned char value;
PyArg_ParseTuple (args, "b", &value)

If you want something that isn't an integer type, you may be able to change the Python object type that is passed to your function, and then use the appropriate format string to get the end result you want.

bde