Return true if the object *o* is a type object, but not a subtype of the
standard type object. Return false in all other cases.
- .. versionadded:: 2.2
-
.. cfunction:: int PyType_HasFeature(PyObject *o, int feature)
Return true if the type object includes support for the cycle detector; this
tests the type flag :const:`Py_TPFLAGS_HAVE_GC`.
- .. versionadded:: 2.0
-
.. cfunction:: int PyType_IsSubtype(PyTypeObject *a, PyTypeObject *b)
Return true if *a* is a subtype of *b*.
- .. versionadded:: 2.2
-
.. cfunction:: PyObject* PyType_GenericAlloc(PyTypeObject *type, Py_ssize_t nitems)
- .. versionadded:: 2.2
+ XXX: Document.
.. cfunction:: PyObject* PyType_GenericNew(PyTypeObject *type, PyObject *args, PyObject *kwds)
- .. versionadded:: 2.2
+ XXX: Document.
.. cfunction:: int PyType_Ready(PyTypeObject *type)
from a type's base class. Return ``0`` on success, or return ``-1`` and sets an
exception on error.
- .. versionadded:: 2.2
-
.. _noneobject:
.. cmacro:: Py_RETURN_NONE
- Properly handle returning :cdata:`Py_None` from within a C function.
-
- .. versionadded:: 2.4
+ Properly handle returning :cdata:`Py_None` from within a C function (that is,
+ increment the reference count of None and return it.)
.. _numericobjects:
Return true if *o* is of type :cdata:`PyInt_Type` or a subtype of
:cdata:`PyInt_Type`.
- .. versionchanged:: 2.2
- Allowed subtypes to be accepted.
-
.. cfunction:: int PyInt_CheckExact(PyObject *o)
Return true if *o* is of type :cdata:`PyInt_Type`, but not a subtype of
:cdata:`PyInt_Type`.
- .. versionadded:: 2.2
-
.. cfunction:: PyObject* PyInt_FromString(char *str, char **pend, int base)
Create a new integer object with a value of *ival*. If the value exceeds
``LONG_MAX``, a long integer object is returned.
- .. versionadded:: 2.5
-
.. cfunction:: long PyInt_AsLong(PyObject *io)
:ctype:`PyLongObject`, if it is not already one, and then return its value as
unsigned long. This function does not check for overflow.
- .. versionadded:: 2.3
-
.. cfunction:: unsigned PY_LONG_LONG PyInt_AsUnsignedLongLongMask(PyObject *io)
:ctype:`PyLongObject`, if it is not already one, and then return its value as
unsigned long long, without checking for overflow.
- .. versionadded:: 2.3
-
.. cfunction:: Py_ssize_t PyInt_AsSsize_t(PyObject *io)
:ctype:`PyLongObject`, if it is not already one, and then return its value as
:ctype:`Py_ssize_t`.
- .. versionadded:: 2.5
-
.. cfunction:: long PyInt_GetMax()
Return true if *o* is of type :cdata:`PyBool_Type`.
- .. versionadded:: 2.3
-
.. cvar:: PyObject* Py_False
Return :const:`Py_False` from a function, properly incrementing its reference
count.
- .. versionadded:: 2.4
-
.. cmacro:: Py_RETURN_TRUE
Return :const:`Py_True` from a function, properly incrementing its reference
count.
- .. versionadded:: 2.4
-
.. cfunction:: PyObject* PyBool_FromLong(long v)
Return a new reference to :const:`Py_True` or :const:`Py_False` depending on the
truth value of *v*.
- .. versionadded:: 2.3
-
.. _longobjects:
Return true if its argument is a :ctype:`PyLongObject` or a subtype of
:ctype:`PyLongObject`.
- .. versionchanged:: 2.2
- Allowed subtypes to be accepted.
-
.. cfunction:: int PyLong_CheckExact(PyObject *p)
Return true if its argument is a :ctype:`PyLongObject`, but not a subtype of
:ctype:`PyLongObject`.
- .. versionadded:: 2.2
-
.. cfunction:: PyObject* PyLong_FromLong(long v)
radix must be in the range [2, 36]; if it is out of range, :exc:`ValueError`
will be raised.
- .. versionadded:: 1.6
-
.. cfunction:: PyObject* PyLong_FromVoidPtr(void *p)
Create a Python integer or long integer from the pointer *p*. The pointer value
can be retrieved from the resulting value using :cfunc:`PyLong_AsVoidPtr`.
-
- .. versionadded:: 1.5.2
-
- .. versionchanged:: 2.5
- If the integer is larger than LONG_MAX, a positive long integer is returned.
+ If the integer is larger than LONG_MAX, a positive long integer is returned.
.. cfunction:: long PyLong_AsLong(PyObject *pylong)
Return a C :ctype:`long long` from a Python long integer. If *pylong* cannot be
represented as a :ctype:`long long`, an :exc:`OverflowError` will be raised.
- .. versionadded:: 2.2
-
.. cfunction:: unsigned PY_LONG_LONG PyLong_AsUnsignedLongLong(PyObject *pylong)
will be raised if the value is positive, or a :exc:`TypeError` will be raised if
the value is negative.
- .. versionadded:: 2.2
-
.. cfunction:: unsigned long PyLong_AsUnsignedLongMask(PyObject *io)
Return a C :ctype:`unsigned long` from a Python long integer, without checking
for overflow.
- .. versionadded:: 2.3
-
.. cfunction:: unsigned PY_LONG_LONG PyLong_AsUnsignedLongLongMask(PyObject *io)
Return a C :ctype:`unsigned long long` from a Python long integer, without
checking for overflow.
- .. versionadded:: 2.3
-
.. cfunction:: double PyLong_AsDouble(PyObject *pylong)
is only assured to produce a usable :ctype:`void` pointer for values created
with :cfunc:`PyLong_FromVoidPtr`.
- .. versionadded:: 1.5.2
-
- .. versionchanged:: 2.5
- For values outside 0..LONG_MAX, both signed and unsigned integers are acccepted.
+ For values outside 0..LONG_MAX, both signed and unsigned integers are acccepted.
.. _floatobjects:
Return true if its argument is a :ctype:`PyFloatObject` or a subtype of
:ctype:`PyFloatObject`.
- .. versionchanged:: 2.2
- Allowed subtypes to be accepted.
-
.. cfunction:: int PyFloat_CheckExact(PyObject *p)
Return true if its argument is a :ctype:`PyFloatObject`, but not a subtype of
:ctype:`PyFloatObject`.
- .. versionadded:: 2.2
-
.. cfunction:: PyObject* PyFloat_FromString(PyObject *str)
Return true if its argument is a :ctype:`PyComplexObject` or a subtype of
:ctype:`PyComplexObject`.
- .. versionchanged:: 2.2
- Allowed subtypes to be accepted.
-
.. cfunction:: int PyComplex_CheckExact(PyObject *p)
Return true if its argument is a :ctype:`PyComplexObject`, but not a subtype of
:ctype:`PyComplexObject`.
- .. versionadded:: 2.2
-
.. cfunction:: PyObject* PyComplex_FromCComplex(Py_complex v)
Return the :ctype:`Py_complex` value of the complex number *op*.
- .. versionchanged:: 2.6
- If *op* is not a Python complex number object but has a :meth:`__complex__`
- method, this method will first be called to convert *op* to a Python complex
- number object.
+ If *op* is not a Python complex number object but has a :meth:`__complex__`
+ method, this method will first be called to convert *op* to a Python complex
+ number object.
.. _sequenceobjects:
Return true if the object *o* is a string object or an instance of a subtype of
the string type.
- .. versionchanged:: 2.2
- Allowed subtypes to be accepted.
-
.. cfunction:: int PyString_CheckExact(PyObject *o)
Return true if the object *o* is a string object, but not an instance of a
subtype of the string type.
- .. versionadded:: 2.2
-
.. cfunction:: PyObject* PyString_FromString(const char *v)
must correspond exactly to the format characters in the *format* string. The
following format characters are allowed:
- .. % This should be exactly the same as the table in PyErr_Format.
+ .. % XXX: This should be exactly the same as the table in PyErr_Format.
.. % One should just refer to the other.
- .. % The descriptions for %zd and %zu are wrong, but the truth is complicated
+ .. % XXX: The descriptions for %zd and %zu are wrong, but the truth is complicated
.. % because not all compilers support the %z width modifier -- we fake it
.. % when necessary via interpolating PY_FORMAT_SIZE_T.
.. % %u, %lu, %zu should have "new in Python 2.5" blurbs.
Return true if the object *o* is a Unicode object or an instance of a Unicode
subtype.
- .. versionchanged:: 2.2
- Allowed subtypes to be accepted.
-
.. cfunction:: int PyUnicode_CheckExact(PyObject *o)
Return true if the object *o* is a Unicode object, but not an instance of a
subtype.
- .. versionadded:: 2.2
-
.. cfunction:: Py_ssize_t PyUnicode_GET_SIZE(PyObject *o)
*NULL*, the return value might be a shared object. Therefore, modification of
the resulting Unicode object is only allowed when *u* is *NULL*.
- .. versionadded:: 3.0
-
.. cfunction:: PyObject *PyUnicode_FromString(const char *u)
Create a Unicode object from an UTF-8 encoded null-terminated char buffer
*u*.
- .. versionadded:: 3.0
-
.. cfunction:: PyObject* PyUnicode_FromFormat(const char *format, ...)
An unrecognized format character causes all the rest of the format string to be
copied as-is to the result string, and any extra arguments discarded.
- .. versionadded:: 3.0
-
.. cfunction:: PyObject* PyUnicode_FromFormatV(const char *format, va_list vargs)
Identical to :func:`PyUnicode_FromFormat` except that it takes exactly two
arguments.
- .. versionadded:: 3.0
-
.. cfunction:: Py_UNICODE* PyUnicode_AsUnicode(PyObject *unicode)
treated as an error. Those bytes will not be decoded and the number of bytes
that have been decoded will be stored in *consumed*.
- .. versionadded:: 2.4
-
.. cfunction:: PyObject* PyUnicode_EncodeUTF8(const Py_UNICODE *s, Py_ssize_t size, const char *errors)
Return *NULL* if an exception was raised by the codec.
- .. versionadded:: 2.6
-
.. cfunction:: PyObject* PyUnicode_DecodeUTF32Stateful(const char *s, Py_ssize_t size, const char *errors, int *byteorder, Py_ssize_t *consumed)
by four) as an error. Those bytes will not be decoded and the number of bytes
that have been decoded will be stored in *consumed*.
- .. versionadded:: 2.6
-
.. cfunction:: PyObject* PyUnicode_EncodeUTF32(const Py_UNICODE *s, Py_ssize_t size, const char *errors, int byteorder)
Return *NULL* if an exception was raised by the codec.
- .. versionadded:: 2.6
-
.. cfunction:: PyObject* PyUnicode_AsUTF32String(PyObject *unicode)
string always starts with a BOM mark. Error handling is "strict". Return
*NULL* if an exception was raised by the codec.
- .. versionadded:: 2.6
-
These are the UTF-16 codec APIs:
split surrogate pair) as an error. Those bytes will not be decoded and the
number of bytes that have been decoded will be stored in *consumed*.
- .. versionadded:: 2.4
-
.. cfunction:: PyObject* PyUnicode_EncodeUTF16(const Py_UNICODE *s, Py_ssize_t size, const char *errors, int byteorder)
Byte values greater that the length of the string and U+FFFE "characters" are
treated as "undefined mapping".
- .. versionchanged:: 2.4
- Allowed unicode string as mapping argument.
-
.. cfunction:: PyObject* PyUnicode_EncodeCharmap(const Py_UNICODE *s, Py_ssize_t size, PyObject *mapping, const char *errors)
trailing lead byte and the number of bytes that have been decoded will be stored
in *consumed*.
- .. versionadded:: 2.5
-
.. cfunction:: PyObject* PyUnicode_EncodeMBCS(const Py_UNICODE *s, Py_ssize_t size, const char *errors)
Return true if *p* is a tuple object or an instance of a subtype of the tuple
type.
- .. versionchanged:: 2.2
- Allowed subtypes to be accepted.
-
.. cfunction:: int PyTuple_CheckExact(PyObject *p)
Return true if *p* is a tuple object, but not an instance of a subtype of the
tuple type.
- .. versionadded:: 2.2
-
.. cfunction:: PyObject* PyTuple_New(Py_ssize_t len)
are initialized to the subsequent *n* C arguments pointing to Python objects.
``PyTuple_Pack(2, a, b)`` is equivalent to ``Py_BuildValue("(OO)", a, b)``.
- .. versionadded:: 2.4
-
.. cfunction:: int PyTuple_Size(PyObject *p)
``*p`` is destroyed. On failure, returns ``-1`` and sets ``*p`` to *NULL*, and
raises :exc:`MemoryError` or :exc:`SystemError`.
- .. versionchanged:: 2.2
- Removed unused third parameter, *last_is_sticky*.
-
.. _listobjects:
Return true if *p* is a list object or an instance of a subtype of the list
type.
- .. versionchanged:: 2.2
- Allowed subtypes to be accepted.
-
.. cfunction:: int PyList_CheckExact(PyObject *p)
Return true if *p* is a list object, but not an instance of a subtype of the
list type.
- .. versionadded:: 2.2
-
.. cfunction:: PyObject* PyList_New(Py_ssize_t len)
Return true if *p* is a dict object or an instance of a subtype of the dict
type.
- .. versionchanged:: 2.2
- Allowed subtypes to be accepted.
-
.. cfunction:: int PyDict_CheckExact(PyObject *p)
Return true if *p* is a dict object, but not an instance of a subtype of the
dict type.
- .. versionadded:: 2.4
-
.. cfunction:: PyObject* PyDict_New()
normally used to create a proxy to prevent modification of the dictionary for
non-dynamic class types.
- .. versionadded:: 2.2
-
.. cfunction:: void PyDict_Clear(PyObject *p)
return ``1``, otherwise return ``0``. On error, return ``-1``. This is
equivalent to the Python expression ``key in p``.
- .. versionadded:: 2.4
-
.. cfunction:: PyObject* PyDict_Copy(PyObject *p)
Return a new dictionary that contains the same key-value pairs as *p*.
- .. versionadded:: 1.6
-
.. cfunction:: int PyDict_SetItem(PyObject *p, PyObject *key, PyObject *val)
if there is not a matching key in *a*. Return ``0`` on success or ``-1`` if an
exception was raised.
- .. versionadded:: 2.2
-
.. cfunction:: int PyDict_Update(PyObject *a, PyObject *b)
This is the same as ``PyDict_Merge(a, b, 1)`` in C, or ``a.update(b)`` in
Python. Return ``0`` on success or ``-1`` if an exception was raised.
- .. versionadded:: 2.2
-
.. cfunction:: int PyDict_MergeFromSeq2(PyObject *a, PyObject *seq2, int override)
if override or key not in a:
a[key] = value
- .. versionadded:: 2.2
-
.. _otherobjects:
Return true if its argument is a :ctype:`PyFileObject` or a subtype of
:ctype:`PyFileObject`.
- .. versionchanged:: 2.2
- Allowed subtypes to be accepted.
-
.. cfunction:: int PyFile_CheckExact(PyObject *p)
Return true if its argument is a :ctype:`PyFileObject`, but not a subtype of
:ctype:`PyFileObject`.
- .. versionadded:: 2.2
-
.. cfunction:: PyObject* PyFile_FromString(char *filename, char *mode)
Set the file's encoding for Unicode output to *enc*. Return 1 on success and 0
on failure.
- .. versionadded:: 2.3
-
.. cfunction:: int PyFile_SoftSpace(PyObject *p, int newflag)
Return true if *p* is a module object, or a subtype of a module object.
- .. versionchanged:: 2.2
- Allowed subtypes to be accepted.
-
.. cfunction:: int PyModule_CheckExact(PyObject *p)
Return true if *p* is a module object, but not a subtype of
:cdata:`PyModule_Type`.
- .. versionadded:: 2.2
-
.. cfunction:: PyObject* PyModule_New(const char *name)
be used from the module's initialization function. This steals a reference to
*value*. Return ``-1`` on error, ``0`` on success.
- .. versionadded:: 2.0
-
.. cfunction:: int PyModule_AddIntConstant(PyObject *module, const char *name, long value)
used from the module's initialization function. Return ``-1`` on error, ``0`` on
success.
- .. versionadded:: 2.0
-
.. cfunction:: int PyModule_AddStringConstant(PyObject *module, const char *name, const char *value)
used from the module's initialization function. The string *value* must be
null-terminated. Return ``-1`` on error, ``0`` on success.
- .. versionadded:: 2.0
-
.. _iterator-objects:
one-argument form of the :func:`iter` built-in function for built-in sequence
types.
- .. versionadded:: 2.2
-
.. cfunction:: int PySeqIter_Check(op)
Return true if the type of *op* is :cdata:`PySeqIter_Type`.
- .. versionadded:: 2.2
-
.. cfunction:: PyObject* PySeqIter_New(PyObject *seq)
iteration ends when the sequence raises :exc:`IndexError` for the subscripting
operation.
- .. versionadded:: 2.2
-
.. cvar:: PyTypeObject PyCallIter_Type
Type object for iterator objects returned by :cfunc:`PyCallIter_New` and the
two-argument form of the :func:`iter` built-in function.
- .. versionadded:: 2.2
-
.. cfunction:: int PyCallIter_Check(op)
Return true if the type of *op* is :cdata:`PyCallIter_Type`.
- .. versionadded:: 2.2
-
.. cfunction:: PyObject* PyCallIter_New(PyObject *callable, PyObject *sentinel)
return the next item in the iteration. When *callable* returns a value equal to
*sentinel*, the iteration will be terminated.
- .. versionadded:: 2.2
-
.. _descriptor-objects:
"Descriptors" are objects that describe some attribute of an object. They are
found in the dictionary of type objects.
+.. XXX document these!
.. cvar:: PyTypeObject PyProperty_Type
The type object for the built-in descriptor types.
- .. versionadded:: 2.2
-
.. cfunction:: PyObject* PyDescr_NewGetSet(PyTypeObject *type, struct PyGetSetDef *getset)
- .. versionadded:: 2.2
-
.. cfunction:: PyObject* PyDescr_NewMember(PyTypeObject *type, struct PyMemberDef *meth)
- .. versionadded:: 2.2
-
.. cfunction:: PyObject* PyDescr_NewMethod(PyTypeObject *type, struct PyMethodDef *meth)
- .. versionadded:: 2.2
-
.. cfunction:: PyObject* PyDescr_NewWrapper(PyTypeObject *type, struct wrapperbase *wrapper, void *wrapped)
- .. versionadded:: 2.2
-
.. cfunction:: PyObject* PyDescr_NewClassMethod(PyTypeObject *type, PyMethodDef *method)
- .. versionadded:: 2.3
-
.. cfunction:: int PyDescr_IsData(PyObject *descr)
false if it describes a method. *descr* must be a descriptor object; there is
no error checking.
- .. versionadded:: 2.2
-
.. cfunction:: PyObject* PyWrapper_New(PyObject *, PyObject *)
- .. versionadded:: 2.2
-
.. _slice-objects:
Returns 0 on success and -1 on error with exception set.
- .. versionadded:: 2.3
-
.. _weakrefobjects:
Return true if *ob* is either a reference or proxy object.
- .. versionadded:: 2.2
-
.. cfunction:: int PyWeakref_CheckRef(ob)
Return true if *ob* is a reference object.
- .. versionadded:: 2.2
-
.. cfunction:: int PyWeakref_CheckProxy(ob)
Return true if *ob* is a proxy object.
- .. versionadded:: 2.2
-
.. cfunction:: PyObject* PyWeakref_NewRef(PyObject *ob, PyObject *callback)
weakly-referencable object, or if *callback* is not callable, ``None``, or
*NULL*, this will return *NULL* and raise :exc:`TypeError`.
- .. versionadded:: 2.2
-
.. cfunction:: PyObject* PyWeakref_NewProxy(PyObject *ob, PyObject *callback)
is not a weakly-referencable object, or if *callback* is not callable,
``None``, or *NULL*, this will return *NULL* and raise :exc:`TypeError`.
- .. versionadded:: 2.2
-
.. cfunction:: PyObject* PyWeakref_GetObject(PyObject *ref)
Return the referenced object from a weak reference, *ref*. If the referent is
no longer live, returns ``None``.
- .. versionadded:: 2.2
-
.. cfunction:: PyObject* PyWeakref_GET_OBJECT(PyObject *ref)
Similar to :cfunc:`PyWeakref_GetObject`, but implemented as a macro that does no
error checking.
- .. versionadded:: 2.2
-
.. _cobjects:
Type-check macros:
-
.. cfunction:: int PyDate_Check(PyObject *ob)
Return true if *ob* is of type :cdata:`PyDateTime_DateType` or a subtype of
:cdata:`PyDateTime_DateType`. *ob* must not be *NULL*.
- .. versionadded:: 2.4
-
.. cfunction:: int PyDate_CheckExact(PyObject *ob)
Return true if *ob* is of type :cdata:`PyDateTime_DateType`. *ob* must not be
*NULL*.
- .. versionadded:: 2.4
-
.. cfunction:: int PyDateTime_Check(PyObject *ob)
Return true if *ob* is of type :cdata:`PyDateTime_DateTimeType` or a subtype of
:cdata:`PyDateTime_DateTimeType`. *ob* must not be *NULL*.
- .. versionadded:: 2.4
-
.. cfunction:: int PyDateTime_CheckExact(PyObject *ob)
Return true if *ob* is of type :cdata:`PyDateTime_DateTimeType`. *ob* must not
be *NULL*.
- .. versionadded:: 2.4
-
.. cfunction:: int PyTime_Check(PyObject *ob)
Return true if *ob* is of type :cdata:`PyDateTime_TimeType` or a subtype of
:cdata:`PyDateTime_TimeType`. *ob* must not be *NULL*.
- .. versionadded:: 2.4
-
.. cfunction:: int PyTime_CheckExact(PyObject *ob)
Return true if *ob* is of type :cdata:`PyDateTime_TimeType`. *ob* must not be
*NULL*.
- .. versionadded:: 2.4
-
.. cfunction:: int PyDelta_Check(PyObject *ob)
Return true if *ob* is of type :cdata:`PyDateTime_DeltaType` or a subtype of
:cdata:`PyDateTime_DeltaType`. *ob* must not be *NULL*.
- .. versionadded:: 2.4
-
.. cfunction:: int PyDelta_CheckExact(PyObject *ob)
Return true if *ob* is of type :cdata:`PyDateTime_DeltaType`. *ob* must not be
*NULL*.
- .. versionadded:: 2.4
-
.. cfunction:: int PyTZInfo_Check(PyObject *ob)
Return true if *ob* is of type :cdata:`PyDateTime_TZInfoType` or a subtype of
:cdata:`PyDateTime_TZInfoType`. *ob* must not be *NULL*.
- .. versionadded:: 2.4
-
.. cfunction:: int PyTZInfo_CheckExact(PyObject *ob)
Return true if *ob* is of type :cdata:`PyDateTime_TZInfoType`. *ob* must not be
*NULL*.
- .. versionadded:: 2.4
Macros to create objects:
-
.. cfunction:: PyObject* PyDate_FromDate(int year, int month, int day)
Return a ``datetime.date`` object with the specified year, month and day.
- .. versionadded:: 2.4
-
.. cfunction:: PyObject* PyDateTime_FromDateAndTime(int year, int month, int day, int hour, int minute, int second, int usecond)
Return a ``datetime.datetime`` object with the specified year, month, day, hour,
minute, second and microsecond.
- .. versionadded:: 2.4
-
.. cfunction:: PyObject* PyTime_FromTime(int hour, int minute, int second, int usecond)
Return a ``datetime.time`` object with the specified hour, minute, second and
microsecond.
- .. versionadded:: 2.4
-
.. cfunction:: PyObject* PyDelta_FromDSU(int days, int seconds, int useconds)
number of microseconds and seconds lie in the ranges documented for
``datetime.timedelta`` objects.
- .. versionadded:: 2.4
Macros to extract fields from date objects. The argument must be an instance of
:cdata:`PyDateTime_Date`, including subclasses (such as
:cdata:`PyDateTime_DateTime`). The argument must not be *NULL*, and the type is
not checked:
-
.. cfunction:: int PyDateTime_GET_YEAR(PyDateTime_Date *o)
Return the year, as a positive int.
- .. versionadded:: 2.4
-
.. cfunction:: int PyDateTime_GET_MONTH(PyDateTime_Date *o)
Return the month, as an int from 1 through 12.
- .. versionadded:: 2.4
-
.. cfunction:: int PyDateTime_GET_DAY(PyDateTime_Date *o)
Return the day, as an int from 1 through 31.
- .. versionadded:: 2.4
Macros to extract fields from datetime objects. The argument must be an
instance of :cdata:`PyDateTime_DateTime`, including subclasses. The argument
must not be *NULL*, and the type is not checked:
-
.. cfunction:: int PyDateTime_DATE_GET_HOUR(PyDateTime_DateTime *o)
Return the hour, as an int from 0 through 23.
- .. versionadded:: 2.4
-
.. cfunction:: int PyDateTime_DATE_GET_MINUTE(PyDateTime_DateTime *o)
Return the minute, as an int from 0 through 59.
- .. versionadded:: 2.4
-
.. cfunction:: int PyDateTime_DATE_GET_SECOND(PyDateTime_DateTime *o)
Return the second, as an int from 0 through 59.
- .. versionadded:: 2.4
-
.. cfunction:: int PyDateTime_DATE_GET_MICROSECOND(PyDateTime_DateTime *o)
Return the microsecond, as an int from 0 through 999999.
- .. versionadded:: 2.4
Macros to extract fields from time objects. The argument must be an instance of
:cdata:`PyDateTime_Time`, including subclasses. The argument must not be *NULL*,
and the type is not checked:
-
.. cfunction:: int PyDateTime_TIME_GET_HOUR(PyDateTime_Time *o)
Return the hour, as an int from 0 through 23.
- .. versionadded:: 2.4
-
.. cfunction:: int PyDateTime_TIME_GET_MINUTE(PyDateTime_Time *o)
Return the minute, as an int from 0 through 59.
- .. versionadded:: 2.4
-
.. cfunction:: int PyDateTime_TIME_GET_SECOND(PyDateTime_Time *o)
Return the second, as an int from 0 through 59.
- .. versionadded:: 2.4
-
.. cfunction:: int PyDateTime_TIME_GET_MICROSECOND(PyDateTime_Time *o)
Return the microsecond, as an int from 0 through 999999.
- .. versionadded:: 2.4
Macros for the convenience of modules implementing the DB API:
-
.. cfunction:: PyObject* PyDateTime_FromTimestamp(PyObject *args)
Create and return a new ``datetime.datetime`` object given an argument tuple
suitable for passing to ``datetime.datetime.fromtimestamp()``.
- .. versionadded:: 2.4
-
.. cfunction:: PyObject* PyDate_FromTimestamp(PyObject *args)
Create and return a new ``datetime.date`` object given an argument tuple
suitable for passing to ``datetime.date.fromtimestamp()``.
- .. versionadded:: 2.4
-
.. _setobjects:
object: set
object: frozenset
-.. versionadded:: 2.5
-
This section details the public API for :class:`set` and :class:`frozenset`
objects. Any functionality not listed below is best accessed using the either
the abstract object protocol (including :cfunc:`PyObject_CallMethod`,
.. index::
single: package variable; __all__
single: __all__ (package variable)
+ single: modules (in module sys)
This is a simplified interface to :cfunc:`PyImport_ImportModuleEx` below,
leaving the *globals* and *locals* arguments set to *NULL*. When the *name*
to find out. Starting with Python 2.4, a failing import of a module no longer
leaves the module in ``sys.modules``.
- .. versionchanged:: 2.4
- failing imports remove incomplete module objects.
-
- .. index:: single: modules (in module sys)
-
.. cfunction:: PyObject* PyImport_ImportModuleEx(char *name, PyObject *globals, PyObject *locals, PyObject *fromlist)
when a submodule of a package was requested is normally the top-level package,
unless a non-empty *fromlist* was given.
- .. versionchanged:: 2.4
- failing imports remove incomplete module objects.
+ Failing imports remove incomplete module objects, like with
+ :cfunc:`PyImport_ImportModule`.
.. cfunction:: PyObject* PyImport_Import(PyObject *name)
- .. index::
- module: rexec
- module: ihooks
-
This is a higher-level interface that calls the current "import hook function".
It invokes the :func:`__import__` function from the ``__builtins__`` of the
current globals. This means that the import is done using whatever import hooks
- are installed in the current environment, e.g. by :mod:`rexec` or :mod:`ihooks`.
+ are installed in the current environment.
.. cfunction:: PyObject* PyImport_ReloadModule(PyObject *m)
If *name* points to a dotted name of the form ``package.module``, any package
structures not already created will still not be created.
- .. versionchanged:: 2.4
- *name* is removed from ``sys.modules`` in error cases.
-
.. cfunction:: long PyImport_GetMagicNumber()
Marshal a :ctype:`long` integer, *value*, to *file*. This will only write the
least-significant 32 bits of *value*; regardless of the size of the native
- :ctype:`long` type.
-
- .. versionchanged:: 2.4
- *version* indicates the file format.
+ :ctype:`long` type. *version* indicates the file format.
.. cfunction:: void PyMarshal_WriteObjectToFile(PyObject *value, FILE *file, int version)
Marshal a Python object, *value*, to *file*.
-
- .. versionchanged:: 2.4
- *version* indicates the file format.
+ *version* indicates the file format.
.. cfunction:: PyObject* PyMarshal_WriteObjectToString(PyObject *value, int version)
Return a string object containing the marshalled representation of *value*.
-
- .. versionchanged:: 2.4
- *version* indicates the file format.
+ *version* indicates the file format.
The following functions allow marshalled values to be read back in.
Convert a Python integer to a tiny int without overflow checking, stored in a C
:ctype:`unsigned char`.
- .. versionadded:: 2.3
-
``h`` (integer) [short int]
Convert a Python integer to a C :ctype:`short int`.
Convert a Python integer to a C :ctype:`unsigned short int`, without overflow
checking.
- .. versionadded:: 2.3
-
``i`` (integer) [int]
Convert a Python integer to a plain C :ctype:`int`.
Convert a Python integer to a C :ctype:`unsigned int`, without overflow
checking.
- .. versionadded:: 2.3
-
``l`` (integer) [long int]
Convert a Python integer to a C :ctype:`long int`.
Convert a Python integer or long integer to a C :ctype:`unsigned long` without
overflow checking.
- .. versionadded:: 2.3
-
``L`` (integer) [PY_LONG_LONG]
Convert a Python integer to a C :ctype:`long long`. This format is only
available on platforms that support :ctype:`long long` (or :ctype:`_int64` on
without overflow checking. This format is only available on platforms that
support :ctype:`unsigned long long` (or :ctype:`unsigned _int64` on Windows).
- .. versionadded:: 2.3
-
``n`` (integer) [Py_ssize_t]
Convert a Python integer or long integer to a C :ctype:`Py_ssize_t`.
- .. versionadded:: 2.5
-
``c`` (string of length 1) [char]
Convert a Python character, represented as a string of length 1, to a C
:ctype:`char`.
in *items*. The C arguments must correspond to the individual format units in
*items*. Format units for sequences may be nested.
- .. note::
-
- Prior to Python version 1.5.2, this format specifier only accepted a tuple
- containing the individual parameters, not an arbitrary sequence. Code which
- previously caused :exc:`TypeError` to be raised here may now proceed without an
- exception. This is not expected to be a problem for existing code.
-
It is possible to pass Python long integers where integers are requested;
however no proper range checking is done --- the most significant bits are
silently truncated when the receiving field is too small to receive the value
PyArg_ParseTuple(args, "O|O:ref", &object, &callback)
- .. versionadded:: 2.2
-
.. cfunction:: PyObject* Py_BuildValue(const char *format, ...)
``n`` (int) [Py_ssize_t]
Convert a C :ctype:`Py_ssize_t` to a Python integer or long integer.
- .. versionadded:: 2.5
-
``c`` (string of length 1) [char]
Convert a C :ctype:`int` representing a character to a Python string of length
1.
:cfunc:`PyOS_ascii_strtod` should typically be used for reading configuration
files or other non-user input that should be locale independent.
- .. versionadded:: 2.4
-
See the Unix man page :manpage:`strtod(2)` for details.
The return value is a pointer to *buffer* with the converted string or NULL if
the conversion failed.
- .. versionadded:: 2.4
-
.. cfunction:: double PyOS_ascii_atof(const char *nptr)
Convert a string to a :ctype:`double` in a locale-independent way.
- .. versionadded:: 2.4
-
See the Unix man page :manpage:`atof(2)` for details.