Is there any solution to force the RawConfigParser.write() method to export the config file with an alphabetical sort?
Even if the original/loaded config file is sorted, the module mixes the section and the options into the sections arbitrarily, and is really annoying to edit manually a huge unsorted config file.
PD: I'm using python 2.6
The configparser module from Python's standard library defines functionality for reading and writing configuration files as used by Microsoft Windows OS. Such files usually have . INI extension.
Call ConfigParser. read(filename) to read the config data from filename into the ConfigParser object. Call ConfigParser. get(section, option) with option as the JSON-encoded list in section to return the raw string value of the list.
Note also that keys in sections are case-insensitive and stored in lowercase 1. It is possible to read several configurations into a single ConfigParser , where the most recently added configuration has the highest priority.
configparser comes from Python 3 and as such it works well with Unicode. The library is generally cleaned up in terms of internal data storage and reading/writing files.
Three solutions:
write()
(just copy this method from the original source and modify it).write()
.See this article for a ordered dict or maybe use this implementation which preserves the original adding order.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With