jncramp / iniparse

Automatically exported from code.google.com/p/iniparse
Other
0 stars 0 forks source link

get_sections and get_options methods for INIConfig and INISection #27

Open GoogleCodeExporter opened 8 years ago

GoogleCodeExporter commented 8 years ago
Hi,

I am starting playing with iniparse and love to access sections and options 
through an object-oriented notation. I may have missed something in the 
documentation but... 2 methods would make my life easier (reading config files 
and feed argparse arguments):

INIConfig.get_sections to list available sections: I am currently using the 
private _sections attribute. It could be as easy as 

    def get_sections(self):
        return self._sections.keys()

INISection.get_options to list avalaible options

Valuable or not?

Jean-Philippe

Original issue reported on code.google.com by jphthier...@gmail.com on 19 Jan 2011 at 7:03

GoogleCodeExporter commented 8 years ago
INIConfig and INISection both have iterator support which does what you are 
wanting here. A thing to remember is that the iterator support is over the 
section/key name, not the section/value. It could be nice if INIConfig had 
(iter)?(items|sections|values) methods and INISection 
(iter)?(items|keys|values) methods, like dict, but that would then reserve some 
names meaning that if you had an INI section or key called "values" (quite 
plausible) you couldn't do ini.values to get it but would rather need to do 
ini['values']. At present there are no properties without leading underscores, 
meaning that there are no clashes unless your INI file includes underscores.

Anyway, in summary:

Instead of INIConfig.get_sections, use list(INIConfig).
Instead of INISection.get_options, use list(INISection).

(Or iterate over them.)

Original comment by chris.morganiser on 4 Jun 2011 at 10:48