Object Protocol¶
-
int
PyObject_Print(PyObject *o, FILE *fp, int flags)¶ Print an object o, on file fp. Returns
-1on error. The flags argument is used to enable certain printing options. The only option currently supported isPy_PRINT_RAW; if given, thestr()of the object is written instead of therepr().
-
int
PyObject_HasAttr(PyObject *o, PyObject *attr_name)¶ Returns
1if o has the attribute attr_name, and0otherwise. This is equivalent to the Python expressionhasattr(o, attr_name). This function always succeeds.
-
int
PyObject_HasAttrString(PyObject *o, const char *attr_name)¶ Returns
1if o has the attribute attr_name, and0otherwise. This is equivalent to the Python expressionhasattr(o, attr_name). This function always succeeds.
-
PyObject*
PyObject_GetAttr(PyObject *o, PyObject *attr_name)¶ - Return value: New reference.
Retrieve an attribute named attr_name from object o. Returns the attribute value on success, or NULL on failure. This is the equivalent of the Python expression
o.attr_name.
-
PyObject*
PyObject_GetAttrString(PyObject *o, const char *attr_name)¶ - Return value: New reference.
Retrieve an attribute named attr_name from object o. Returns the attribute value on success, or NULL on failure. This is the equivalent of the Python expression
o.attr_name.
-
PyObject*
PyObject_GenericGetAttr(PyObject *o, PyObject *name)¶ Generic attribute getter function that is meant to be put into a type object’s
tp_getattroslot. It looks for a descriptor in the dictionary of classes in the object’s MRO as well as an attribute in the object’s__dict__(if present). As outlined in Implementing Descriptors, data descriptors take preference over instance attributes, while non-data descriptors don’t. Otherwise, anAttributeErroris raised.
-
int
PyObject_SetAttr(PyObject *o, PyObject *attr_name, PyObject *v)¶ Set the value of the attribute named attr_name, for object o, to the value v. Raise an exception and return
-1on failure; return0on success. This is the equivalent of the Python statemento.attr_name = v.If v is NULL, the attribute is deleted, however this feature is deprecated in favour of using
PyObject_DelAttr().
-
int
PyObject_SetAttrString(PyObject *o, const char *attr_name, PyObject *v)¶ Set the value of the attribute named attr_name, for object o, to the value v. Raise an exception and return
-1on failure; return0on success. This is the equivalent of the Python statemento.attr_name = v.If v is NULL, the attribute is deleted, however this feature is deprecated in favour of using
PyObject_DelAttrString().
-
int
PyObject_GenericSetAttr(PyObject *o, PyObject *name, PyObject *value)¶ Generic attribute setter and deleter function that is meant to be put into a type object’s
tp_setattroslot. It looks for a data descriptor in the dictionary of classes in the object’s MRO, and if found it takes preference over setting or deleting the attribute in the instance dictionary. Otherwise, the attribute is set or deleted in the object’s__dict__(if present). On success,0is returned, otherwise anAttributeErroris raised and-1is returned.
-
int
PyObject_DelAttr(PyObject *o, PyObject *attr_name)¶ Delete attribute named attr_name, for object o. Returns
-1on failure. This is the equivalent of the Python statementdel o.attr_name.
