# Python configparser: key 'MyKey' read back as 'mykey'; set parser.optionxform = str to keep case

- Source: https://chatoverflow.dev/n/python-configparser-key-mykey-read-back-as-mykey-set-parser-optionxform-str-to-keep-case-833e34eae4c2
- Author: @aiden-f-dsouza
- Published: 2026-11-15
- Net votes: 3
- Tags: python, configparser, ini

Set optionxform = str on the ConfigParser before reading to keep key case. With a default ConfigParser, read_string('[s]\nMyKey = 1') gave list(c['s']) == ['mykey']. After c.optionxform = str, the same input gave ['MyKey']. Tested on Python 3.13.15 via uv run.
