Objets tableau d'octets

type PyByteArrayObject

Ce sous-type de PyObject représente un objet bytearray Python.

PyTypeObject PyByteArray_Type
Fait partie de l' ABI stable.

Cette instance de PyTypeObject représente le type Python bytearray, c'est le même que bytearray côté Python.

Macros de vérification de type

int PyByteArray_Check(PyObject *o)

Renvoie vrai si l'objet o est un bytearray ou une instance d'un sous-type du type bytearray. Cette méthode réussit toujours.

int PyByteArray_CheckExact(PyObject *o)

Renvoie vrai si l'objet o est un bytearray, mais pas une instance d'un sous-type du type bytearray. Cette méthode réussit toujours.

Fonctions directes sur l'API

PyObject *PyByteArray_FromObject(PyObject *o)
Valeur de retour : nouvelle référence. Fait partie de l' ABI stable. Thread safety: Safe for concurrent use on the same object.

Renvoie un nouvel objet bytearray depuis n'importe quel objet, o, qui implémente le protocole buffer.

On failure, return NULL with an exception set.

Note

If the object implements the buffer protocol, then the buffer must not be mutated while the bytearray object is being created.

PyObject *PyByteArray_FromStringAndSize(const char *string, Py_ssize_t len)
Valeur de retour : nouvelle référence. Fait partie de l' ABI stable. Thread safety: Atomic.

Create a new bytearray object from string and its length, len.

On failure, return NULL with an exception set.

PyObject *PyByteArray_Concat(PyObject *a, PyObject *b)
Valeur de retour : nouvelle référence. Fait partie de l' ABI stable. Thread safety: Safe for concurrent use on the same object.

Concatène les bytearrays a et b et renvoie un nouveau bytearray avec le résultat.

On failure, return NULL with an exception set.

Note

If the object implements the buffer protocol, then the buffer must not be mutated while the bytearray object is being created.

Py_ssize_t PyByteArray_Size(PyObject *bytearray)
Fait partie de l' ABI stable. Thread safety: Atomic.

Renvoie la taille de bytearray après vérification de la présence d'un pointeur NULL.

char *PyByteArray_AsString(PyObject *bytearray)
Fait partie de l' ABI stable. Thread safety: Safe to call from multiple threads with external synchronization only.

Renvoie le contenu de bytearray sous forme d'un tableau de caractères, en vérifiant que ce n'est pas un pointeur NULL. Le tableau renvoyé a toujours un caractère null rajouté.

Note

It is not thread-safe to mutate the bytearray object while using the returned char array.

int PyByteArray_Resize(PyObject *bytearray, Py_ssize_t len)
Fait partie de l' ABI stable.

Resize the internal buffer of bytearray to len. Failure is a -1 return with an exception set.

Modifié dans la version 3.14: A negative len will now result in an exception being set and -1 returned.

Macros

Ces macros sont taillées pour la vitesse d'exécution et ne vérifient pas les pointeurs.

char *PyByteArray_AS_STRING(PyObject *bytearray)
Thread safety: Safe to call from multiple threads with external synchronization only.

Similar to PyByteArray_AsString(), but without error checking.

Note

It is not thread-safe to mutate the bytearray object while using the returned char array.

Py_ssize_t PyByteArray_GET_SIZE(PyObject *bytearray)
Thread safety: Atomic.

Similar to PyByteArray_Size(), but without error checking.