2

i'm currently facing a problem when trying to retrieve the value returned by my python code.

A draft of my code is :

# I call a function that returns a PyObject
PyObject* pyObj_val = call_binding(...);

# This PyObject seems to be a PyInt as PyInt_Check returns 1
assert(PyInt_Check(pyObj_val) == 1);

# Now the only way i found to convert this PyInt to a [C] int is:
int my_val = (int) PyInt_AsLong(pyObj_val);

I suppose there is a way to perform this without going through a long convertion and int cast. Does anyone know about it ?

Thanks for considering my request.

Sebastien M
  • 61
  • 1
  • 8

1 Answers1

1

Simply said: no, that's the way to go about it. There is no separate PyInt_AsInt function.

AKX
  • 152,115
  • 15
  • 115
  • 172