0

Is there a way to find out the type of a Python Object in C extension? I need to pass a name(string) or a double value from script to my extension. I thought I could call parsetuple in my extension and get the argument into a Python Object(using format string "O"), and check to see what the type is, and use it accordingly, but have not been able to find anything on that. I did search the site for answers. If you know this has already been answered, please provide a link, asking me to go search again will not be productive. Thanks.

HJR1
  • 1
  • 1

1 Answers1

0

Assuming Python 3.x.

You can use PyUnicode_Check() to check if the object is a string, then the PyUnicode_AsXXX() functions (documented on the same page) or one of the parse tuple functions.

Similarly with PyFloat_Check() for floating point numbers.

sterin
  • 1,898
  • 15
  • 13