Python Forum

Full Version: using alternate names in configparser
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
an INI i am using configparser to read, modify, and write back has, in each section an option "Name" with a string value that is unique over the entire file. i would like to access each section using that name instead of the one that is normally used. the file i am accessing is "~/.mozilla/firefox/profiles.ini" (just so you know what i am doing).
You can create a dictionary Name member --> section name by traversing the sections. By the way in my profiles.ini, some sections don't have a Name entry.
After reading the INI file you can duplicate the sections replacing section name with value of Name. That said I really don't see the benefit of what you try to do. Why not just use Name value as section name in first place?
there are a couple "control" sections w/o Name option. i don't need to access any section that does not have a Name option.
Then duplicate only sections that have Name option. Still doesn't make sense..
Actually this will work only if you don't want to change configuration from within the script and write it back. If you do it will complicate things.
@Gribouillis idea for a mapping between section and name and name and section with custom get and set functions may work better. Or write your own class and inherit from ConfigParser class
i just made and populated a dict as a section name map. all references by browser profile name are just mapped by that dict so the methods are given the section name. simple enough.