ID EN
Config Parser

optionxform

Python 3.11 🇮🇩 Bahasa Indonesia

Metode ini mengubah nama opsi pada setiap operasi baca, dapatkan, atau setel. Defaultnya mengubah nama menjadi huruf kecil. Ini juga berarti bahwa ketika file konfigurasi ditulis, semua kunci akan menggunakan huruf kecil. Ganti metode ini jika tidak sesuai. Misalnya:

Syntax

PYTHON
ConfigParser.optionxform(option)

Contoh

Example 1
PYTHON
>>> config = """
... [Section1]
... Key = Value
...
... [Section2]
... AnotherKey = Value
... """
>>> typical = configparser.ConfigParser()
>>> typical.read_string(config)
>>> list(typical['Section1'].keys())
['key']
>>> list(typical['Section2'].keys())
['anotherkey']
>>> custom = configparser.RawConfigParser()
>>> custom.optionxform = lambda option: option
>>> custom.read_string(config)
>>> list(custom['Section1'].keys())
['Key']
>>> list(custom['Section2'].keys())
['AnotherKey']