Python Forum
using alternate names in configparser
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
using alternate names in configparser
#1
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).
Tradition is peer pressure from dead people

What do you call someone who speaks three languages? Trilingual. Two languages? Bilingual. One language? American.
Reply
#2
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.
Reply
#3
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?
If you can't explain it to a six year old, you don't understand it yourself, Albert Einstein
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs

Reply
#4
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.
Tradition is peer pressure from dead people

What do you call someone who speaks three languages? Trilingual. Two languages? Bilingual. One language? American.
Reply
#5
Then duplicate only sections that have Name option. Still doesn't make sense..
If you can't explain it to a six year old, you don't understand it yourself, Albert Einstein
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs

Reply
#6
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
If you can't explain it to a six year old, you don't understand it yourself, Albert Einstein
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs

Reply
#7
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.
Tradition is peer pressure from dead people

What do you call someone who speaks three languages? Trilingual. Two languages? Bilingual. One language? American.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  ConfigParser(dict_type=) not behaving as expected malonn 5 3,308 Sep-08-2022, 08:42 AM
Last Post: malonn
  pip unistall in alternate roots confminn 0 1,445 Aug-21-2020, 08:03 PM
Last Post: confminn
  Alternate package of win32com.client manigandanpro 0 3,774 Aug-19-2020, 07:38 AM
Last Post: manigandanpro
Question configparser.NoSectionError (Python 3.7) alpho 2 5,814 Apr-08-2020, 10:26 PM
Last Post: micseydel
  Error in configparser fullstop 12 9,980 Dec-22-2019, 07:36 PM
Last Post: snippsat
  Alternate solutions to cipher problem? Mark17 3 2,419 Oct-08-2019, 01:32 PM
Last Post: jefsummers
  Help with ConfigParser EricALionsFan 3 3,257 Jul-27-2018, 08:46 PM
Last Post: buran
  ConfigParser.NoSectionError: No section: 'Default' degenaro 1 14,465 Jun-08-2018, 08:33 PM
Last Post: ljmetzger
  No module named 'ConfigParser' Bani 13 56,245 May-22-2017, 08:02 PM
Last Post: Ofnuts

Forum Jump:

User Panel Messages

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