Teks sumber — English
Terjemahan — Bahasa Indonesia
Custom type converters
Konverter tipe kustom
The :mod:`argparse` module allows you to specify custom type converters for your command-line arguments. This allows you to modify user input before it's stored in the :class:`argparse.Namespace`. This can be useful when you need to pre-process the input before it is used in your program.
Modul :mod:`argparse` memungkinkan Anda menentukan konverter tipe kustom untuk argumen baris perintah Anda. Hal ini memungkinkan Anda memodifikasi input pengguna sebelum disimpan dalam :class:`argparse.Namespace`. Ini bisa berguna saat Anda perlu memproses input terlebih dahulu sebelum digunakan dalam program Anda.
Defined two arguments, ``-a`` and ``+a``, which used the ``type`` parameter to create custom type converters to store the value in a tuple with the prefix.
Mendefinisikan dua argumen, ``-a`` dan ``+a``, yang menggunakan parameter ``type`` untuk membuat konverter tipe kustom guna menyimpan nilai dalam sebuah tuple beserta prefiksnya.
Without the custom type converters, the arguments would have treated the ``-a`` and ``+a`` as the same argument, which would have been undesirable. By using custom type converters, we were able to differentiate between the two arguments.
Tanpa konverter tipe kustom, argumen-argumen tersebut akan memperlakukan ``-a`` dan ``+a`` sebagai argumen yang sama, yang tentunya tidak diinginkan. Dengan menggunakan konverter tipe kustom, kita dapat membedakan kedua argumen tersebut.