Pelokalan
Python ID
id en
Masuk
Proyek
c-api__buffer.po Berkas proyek · python-docs-id-3.14 · Bahasa Indonesia
Modul PO Hanya lihat
Teks sumber — English
Terjemahan — Bahasa Indonesia
on the producer side, a type can export a "buffer interface" which allows objects of that type to expose information about their underlying buffer. This interface is described in the section :ref:`buffer-structs`; for Python see :ref:`python-buffer-protocol`.
call :c:func:`PyArg_ParseTuple` (or one of its siblings) with one of the ``y*``, ``w*`` or ``s*`` :ref:`format codes <arg-parsing>`.
Buffer structures (or simply "buffers") are useful as a way to expose the binary data from another object to the Python programmer. They can also be used as a zero-copy slicing mechanism. Using their ability to reference a block of memory, it is possible to expose any data to the Python programmer quite easily. The memory could be a large, constant array in a C extension, it could be a raw block of memory for manipulation before passing to an operating system library, or it could be used to pass around structured data in its native, in-memory format.
Item size in bytes of a single element. Same as the value of :func:`struct.calcsize` called on non-``NULL`` :c:member:`~Py_buffer.format` values.
Important exception: If a consumer requests a buffer without the :c:macro:`PyBUF_FORMAT` flag, :c:member:`~Py_buffer.format` will be set to ``NULL``, but :c:member:`~Py_buffer.itemsize` still has the value for the original format.
This field is controlled by the :c:macro:`PyBUF_FORMAT` flag.
Shape values are restricted to ``shape[n] >= 0``. The case ``shape[n] == 0`` requires special attention. See `complex arrays`_ for further information.
Stride values can be any integer. For regular arrays, strides are usually positive, but a consumer MUST be able to handle the case ``strides[n] <= 0``. See `complex arrays`_ for further information.
This type of array representation is used by the Python Imaging Library (PIL). See `complex arrays`_ for further information how to access elements of such an array.
readonly, format
Controls the :c:member:`~Py_buffer.format` field. If set, this field MUST be filled in correctly. Otherwise, this field MUST be ``NULL``.
:c:macro:`PyBUF_FORMAT` must be \|'d to any of the flags except :c:macro:`PyBUF_SIMPLE`, because the latter already implies format ``B`` (unsigned bytes). :c:macro:`!PyBUF_FORMAT` cannot be used on its own.
C or Fortran :term:`contiguity <contiguous>` can be explicitly requested, with and without stride information. Without stride information, the buffer must be C-contiguous.
format
format
Return the implied :c:member:`~Py_buffer.itemsize` from :c:member:`~Py_buffer.format`. On error, raise an exception and return -1.