![]() |
| using alternate names in configparser - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: General Coding Help (https://python-forum.io/forum-8.html) +--- Thread: using alternate names in configparser (/thread-30031.html) |
using alternate names in configparser - Skaperen - Oct-01-2020 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). RE: using alternate names in configparser - Gribouillis - Oct-01-2020 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. RE: using alternate names in configparser - buran - Oct-01-2020 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? RE: using alternate names in configparser - Skaperen - Oct-01-2020 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. RE: using alternate names in configparser - buran - Oct-01-2020 Then duplicate only sections that have Name option. Still doesn't make sense.. RE: using alternate names in configparser - buran - Oct-01-2020 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 RE: using alternate names in configparser - Skaperen - Oct-01-2020 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. |