Pelokalan
Python ID
id en
Masuk
Proyek
c-api__arg.po Berkas proyek · python-docs-id-3.14 · Bahasa Indonesia
Modul PO Hanya lihat
Teks sumber — English
Terjemahan — Bahasa Indonesia
The first three of these functions described, :c:func:`PyArg_ParseTuple`, :c:func:`PyArg_ParseTupleAndKeywords`, and :c:func:`PyArg_Parse`, all use *format strings* which are used to tell the function about the expected arguments. The format strings use the same syntax for each of these functions.
Tiga fungsi pertama dijelaskan yaitu, :c:func:`PyArg_ParseTuple`, :c:func:`PyArg_ParseTupleAndKeywords`, dan :c:func:`PyArg_Parse`, semuanya menggunakan *format string* yang digunakan untuk memberitahu fungsi tentang expected argumen . Format string menggunakan sintaks yang sama untuk setiap fungsi tersebut.
A format string consists of zero or more "format units." A format unit describes one Python object; it is usually a single character or a parenthesized sequence of format units. With a few exceptions, a format unit that is not a parenthesized sequence normally corresponds to a single address argument to these functions. In the following description, the quoted form is the format unit; the entry in (round) parentheses is the Python object type that matches the format unit; and the entry in [square] brackets is the type of the C variable(s) whose address should be passed.
format string terdiri dari nol atau lebih "unit format." Sebuah unit format menjelaskan satu obyek Python; Seringkali adalah sebuah karaketer atau sebuah urutan unit format yang di dalam kurung. Dengan beberapa pengecualian, format unit yang bukan sebuah urutan yang di dalam kurung biasanya berhubungan dengan sebuah argumen yang memanggil fungsi-fungsi ini. Dalam penjelasan berikut ini, bentuk yang dikutip adalah unit format. Entri yang di dalam kurung (bulat) adalah tipe obyek Python yang cocok dengan unit format, dan entri yang di dalam kurung [kotak] adalah tipe variabel C yang perlu dipanggil.
A few other characters have a meaning in a format string. These may not occur inside nested parentheses. They are:
Kilka innych znaków ma jeszcze znaczenie w ciągu formatu. Nie mogą one wystąpić wewnątrz zagnieżdżonych nawiasach okrągłych. Są to:
Indicates that the remaining arguments in the Python argument list are optional. The C variables corresponding to optional arguments should be initialized to their default value --- when an optional argument is not specified, :c:func:`PyArg_ParseTuple` does not touch the contents of the corresponding C variable(s). For example, the format string ``"OO|OO"`` corresponds to the Python signature ``f(a, b, c=None, d=None)``.
:c:func:`PyArg_ParseTupleAndKeywords` only: Indicates that the remaining arguments in the Python argument list are keyword-only. They are optional if ``|`` was specified before ``$``, and required otherwise. ``|`` cannot be specified after ``$``. For example, the format string ``"O|O$O"`` corresponds to the Python signature ``f(a, b=None, *, c=None)``, and the format string ``"OO$OO"`` corresponds to ``f(a, b, *, c, d)``.
Additional arguments passed to these functions must be addresses of variables whose type is determined by the format string; these are used to store values from the input tuple. There are a few cases, as described in the list of format units above, where these parameters are used as input values; they should match what is specified for the corresponding format unit in that case.
Dodatkowe parametry przekazywane do tych funkcji muszą być adresami zmiennych których typ jest określany przez ciąg formatu; są one używane do przechowywania wartości z krotki wejściowej. Jest parę przypadków, jak opisuje to lista jednostek formatu powyżej, gdzie te parametry są używane jako wprowadzane wartości; w takich przypadku powinny one odpowiadać temu, co jest określone we właściwych im jednostach formatu.
A simpler form of parameter retrieval which does not use a format string to specify the types of the arguments. Functions which use this method to retrieve their parameters should be declared as :c:macro:`METH_VARARGS` in function or method tables. The tuple containing the actual parameters should be passed as *args*; it must actually be a tuple. The length of the tuple must be at least *min* and no more than *max*; *min* and *max* may be equal. Additional arguments must be passed to the function, each of which should be a pointer to a :c:expr:`PyObject*` variable; these will be filled in with the values from *args*; they will contain :term:`borrowed references <borrowed reference>`. The variables which correspond to optional parameters not given by *args* will not be filled in; these should be initialized by the caller. This function returns true on success and false if *args* is not a tuple or contains the wrong number of elements; an exception will be set if there was a failure.
Bentuk pengambilan parameter yang lebih sederhana yang tidak menggunakan string format untuk menentukan jenis argumen. Fungsi yang menggunakan metode ini untuk mengambil parameter harus dideklarasikan sebagai :c:macro:`METH_VARARGS` dalam tabel fungsi atau metode. Tuple yang berisi parameter aktual harus diberikan sebagai * args*; harus benar-benar sebuah tuple. Panjang tuple harus setidaknya *min* dan tidak lebih dari *max*; nilsi *min* dan *max* boleh sama. Argumen tambahan harus dilewatkan ke fungsi, yang masing-masing harus berupa penunjuk ke variabel :c:expr:`PyObject*`; ini akan diisi dengan nilai dari *args*; mereka akan berisi :term: `referensi yang dipinjam <borrowed reference>`. Variabel-variabel yang berhubungan dengan parameter opsional yang tidak diberikan oleh *args* tidak akan diisi; variabel-variabel ini harus diinisialisasi oleh pemanggil. Fungsi ini mengembalikan nilai true jika berhasil dan false jika *args* bukan sebuah tuple atau berisi jumlah elemen yang salah; sebuah pengecualian akan ditetapkan jika terjadi kegagalan.
Create a new value based on a format string similar to those accepted by the ``PyArg_Parse*`` family of functions and a sequence of values. Returns the value or ``NULL`` in the case of an error; an exception will be raised if ``NULL`` is returned.
Membuat nilai baru berdasarkan string format yang mirip dengan yang diterima oleh keluarga fungsi ``PyArg_Parse*`` dan urutan nilai. Mengembalikan nilai atau ``NULL`` jika terjadi kesalahan; pengecualian akan dimunculkan jika ``NULL`` dikembalikan.
:c:func:`Py_BuildValue` does not always build a tuple. It builds a tuple only if its format string contains two or more format units. If the format string is empty, it returns ``None``; if it contains exactly one format unit, it returns whatever object is described by that format unit. To force it to return a tuple of size 0 or one, parenthesize the format string.
The characters space, tab, colon and comma are ignored in format strings (but not within format units such as ``s#``). This can be used to make long format strings a tad more readable.
If there is an error in the format string, the :exc:`SystemError` exception is set and ``NULL`` returned.