Integer Conversion¶
Legacy Wiki Page
This page was migrated from the old MoinMoin-based wiki. Information may be outdated or no longer applicable. For current documentation, see python.org.
CPython function |
Jython method |
|---|---|
int PyObject.asInt() |
|
PyObject* intobject::PyInt_FromString(char *s, char **pend, int base) |
|
Py_ssize_t intobject::PyInt_AsSsize_t(register PyObject *op) |
int PyObject. |
Py_ssize_t abstract::PyNumber_AsSsize_t(PyObject *item, PyObject *err) |
int PyObject.asIndex(err) |
boolean PyObject.isIndex() |
When using asInt, consider whether you want to ensure the original object is an instanceof PyInteger/PyLong prior to calling asInt on it. It’s common to do this check before calling asInt, but is not required – otherwise asInt will attempt to implicitly convert non int/longs via user defined __int__ methods.