This wiki is in the process of being archived due to lack of usage and the resources necessary to serve it — predominately to bots, crawlers, and LLM companies. Edits are discouraged.
Pages are preserved as they were at the time of archival. For current information, please visit python.org.
If a change to this archive is absolutely needed, requests can be made via the infrastructure@python.org mailing list.

CPython function

Jython method

long intobject::PyInt_AsLong(register PyObject *op)

int PyObject.asInt()

PyObject* intobject::PyInt_FromString(char *s, char **pend, int base)

PyObject PyObject.__int__()

Py_ssize_t intobject::PyInt_AsSsize_t(register PyObject *op)

int PyObject.__int__().asInt()

Py_ssize_t abstract::PyNumber_AsSsize_t(PyObject *item, PyObject *err)

int PyObject.asIndex(err)

int abstract.h::PyIndex_Check(PyObject *ob)

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.


2026-02-14 16:30