Python Forum
case transparent names in configpaser
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
case transparent names in configpaser
#2
You can override optionxform. There's a section in the docs about doing this.

Quote:ConfigParser.optionxform(option)

This method transforms option names on every read, get, or set operation. The default converts the name to lowercase. This also means that when a configuration file gets written, all keys will be lowercase. Override this method if that’s unsuitable. For example:

>>> 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']
Reply


Messages In This Thread
case transparent names in configpaser - by Skaperen - Oct-01-2020, 08:35 PM
RE: case transparent names in configpaser - by bowlofred - Oct-01-2020, 09:08 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Display transparent image as overlay jds8086 0 1,297 Apr-17-2022, 11:43 AM
Last Post: jds8086
  Switch case or match case? Frankduc 9 4,727 Jan-20-2022, 01:56 PM
Last Post: Frankduc

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020