Pelokalan
Python ID
id en
Masuk
Proyek
c-api__unicode.po Berkas proyek · python-docs-id-3.14 · Bahasa Indonesia
Modul PO Hanya lihat
Teks sumber — English
Terjemahan — Bahasa Indonesia
The :c:type:`Py_UNICODE` representation has been removed since Python 3.12 with deprecated APIs. See :pep:`623` for more information.
Unicode Type
Tipe Unicode
These are the basic Unicode object types used for the Unicode implementation in Python:
This instance of :c:type:`PyTypeObject` represents the Python Unicode type. It is exposed to Python code as :py:class:`str`.
This instance of :c:type:`PyTypeObject` represents the Python Unicode iterator type. It is used to iterate over Unicode string objects.
These types are typedefs for unsigned integer types wide enough to contain characters of 32 bits, 16 bits and 8 bits, respectively. When dealing with single Unicode characters, use :c:type:`Py_UCS4`.
These subtypes of :c:type:`PyObject` represent a Python Unicode object. In almost all cases, they shouldn't be used directly, since all API functions that deal with Unicode objects take and return :c:type:`PyObject` pointers.
Return true if the object *obj* is a Unicode object or an instance of a Unicode subtype. This function always succeeds.
Return true if the object *obj* is a Unicode object, but not an instance of a subtype. This function always succeeds.
Return a pointer to the canonical representation cast to UCS1, UCS2 or UCS4 integer types for direct character access. No checks are performed if the canonical representation has the correct character size; use :c:func:`PyUnicode_KIND` to select the right function.
Join two surrogate code points and return a single :c:type:`Py_UCS4` value. *high* and *low* are respectively the leading and trailing surrogates in a surrogate pair. *high* must be in the range ``[0xD800; 0xDBFF]`` and *low* must be in the range ``[0xDC00; 0xDFFF]``.
To avoid accidentally exposing a partially-written string object, prefer using the :c:type:`PyUnicodeWriter` API, or one of the ``PyUnicode_From*`` functions below.
Take a C :c:func:`printf`\ -style *format* string and a variable number of arguments, calculate the size of the resulting Python Unicode string and return a string with the values formatted into it. The variable arguments must be C types and must correspond exactly to the format characters in the *format* ASCII-encoded string.
Conversion flags (optional), which affect the result of some conversion types.
Minimum field width (optional). If specified as an ``'*'`` (asterisk), the actual width is given in the next argument, which must be of type :c:expr:`int`, and the object to convert comes after the minimum field width and optional precision.
Precision (optional), given as a ``'.'`` (dot) followed by the precision. If specified as ``'*'`` (an asterisk), the actual precision is given in the next argument, which must be of type :c:expr:`int`, and the value to convert comes after the precision.
Conversion type.
The length modifiers for following integer conversions (``d``, ``i``, ``o``, ``u``, ``x``, or ``X``) specify the type of the argument (:c:expr:`int` by default):
Types
Tipe-tipe
:c:type:`intmax_t` or :c:type:`uintmax_t`
:c:type:`size_t` or :c:type:`ssize_t`
:c:type:`ptrdiff_t`
The length modifier ``l`` for following conversions ``s`` or ``V`` specify that the type of the argument is :c:expr:`const wchar_t*`.
Type
Typ
Get the fully qualified name of an object type; call :c:func:`PyType_GetFullyQualifiedName`.
:c:expr:`PyTypeObject*`
Get the fully qualified name of a type; call :c:func:`PyType_GetFullyQualifiedName`.
The width formatter unit is number of characters rather than bytes. The precision formatter unit is number of bytes or :c:type:`wchar_t` items (if the length modifier ``l`` is used) for ``"%s"`` and ``"%V"`` (if the ``PyObject*`` argument is ``NULL``), and a number of characters for ``"%A"``, ``"%U"``, ``"%S"``, ``"%R"`` and ``"%V"`` (if the ``PyObject*`` argument is not ``NULL``).
Copy an instance of a Unicode subtype to a new true Unicode object if necessary. If *obj* is already a true Unicode object (not a subtype), return a new :term:`strong reference` to the object.
Objects other than Unicode or its subtypes will cause a :exc:`TypeError`.
All other objects, including Unicode objects, cause a :exc:`TypeError` to be set.
Return a mapping suitable for decoding a custom single-byte encoding. Given a Unicode string *string* of up to 256 characters representing an encoding table, returns either a compact internal mapping object or a dictionary mapping character ordinals to byte values. Raises a :exc:`TypeError` and return ``NULL`` on invalid input.
:ref:`PyArg_Parse\* converter <arg-parsing>`: encode :class:`str` objects -- obtained directly or through the :class:`os.PathLike` interface -- to :class:`bytes` using :c:func:`PyUnicode_EncodeFSDefault`; :class:`bytes` objects are output as-is. *result* must be an address of a C variable of type :c:expr:`PyObject*` (or :c:expr:`PyBytesObject*`). On success, set the variable to a new :term:`strong reference` to a :ref:`bytes object <bytesobjects>` which must be released when it is no longer used and return a non-zero value (:c:macro:`Py_CLEANUP_SUPPORTED`). Embedded null bytes are not allowed in the result. On failure, return ``0`` with an exception set.
:ref:`PyArg_Parse\* converter <arg-parsing>`: decode :class:`bytes` objects -- obtained either directly or indirectly through the :class:`os.PathLike` interface -- to :class:`str` using :c:func:`PyUnicode_DecodeFSDefaultAndSize`; :class:`str` objects are output as-is. *result* must be an address of a C variable of type :c:expr:`PyObject*` (or :c:expr:`PyUnicodeObject*`). On success, set the variable to a new :term:`strong reference` to a :ref:`Unicode object <unicodeobjects>` which must be released when it is no longer used and return a non-zero value (:c:macro:`Py_CLEANUP_SUPPORTED`). Embedded null characters are not allowed in the result. On failure, return ``0`` with an exception set.
:c:type:`wchar_t` support for platforms which support it:
Create a Unicode object from the :c:type:`wchar_t` buffer *wstr* of the given *size*. Passing ``-1`` as the *size* indicates that the function must itself compute the length, using :c:func:`!wcslen`. Return ``NULL`` on failure.
Copy the Unicode object contents into the :c:type:`wchar_t` buffer *wstr*. At most *size* :c:type:`wchar_t` characters are copied (excluding a possibly trailing null termination character). Return the number of :c:type:`wchar_t` characters copied or ``-1`` in case of an error.
Convert the Unicode object to a wide character string. The output string always ends with a null character. If *size* is not ``NULL``, write the number of wide characters (excluding the trailing null termination character) into *\*size*. Note that the resulting :c:type:`wchar_t` string might contain null characters, which would cause the string to be truncated when used with most C functions. If *size* is ``NULL`` and the :c:expr:`wchar_t*` string contains null characters a :exc:`ValueError` is raised.
The return type is now ``const char *`` rather than ``char *``.
Set a :exc:`TypeError` exception and return ``-1`` if *a* or *b* is not a :class:`str` object.
:c:data:`Py_NotImplemented` in case the type combination is unknown
The :c:type:`PyUnicodeWriter` API can be used to create a Python :class:`str` object.
This is a typedef of :c:type:`wchar_t`, which is a 16-bit type or 32-bit type depending on the platform. Please use :c:type:`wchar_t` directly instead.
In previous versions, this was a 16-bit type or a 32-bit type depending on whether you selected a "narrow" or "wide" Unicode version of Python at build time.