Re: ConfigParser y secciones en mayuscula/minuscula

Arnau Sanchez <[email protected]>
Newsgroups gmane.comp.python.general.castellano
Message-ID <[email protected]>
Renato Covarrubias Romero wrote:

> from ConfigParser import ConfigParser
> 
> class IncaseConfigParser(ConfigParser):
>   def get(self, section, option, raw=False, vars=None):
>     for s in self.sections():
>       if s.lower() == section.lower():
>         for o in self.options(s):
>           if o.lower() == option.lower():
>             return ConfigParser.get(self, s, o, raw, vars)
>     return None

Pensé en heredar, pero una solución completa obligaría, en principio, a 
implementar también getint, getboolean, getfloat, has_section, has_option, etc. 
Si realmente sólo va a hacer a hacer gets simples, con tu solución le basta y le 
sobra.

arnau

pd: mirando el código se puede comprobar que los getX() acaban pasando por 
get(), así que también esas funciones responderán bien (queda en el aire si la 
implementación está obligada siempre a funcionar así o no):

     def getint(self, section, option):
         return self._get(section, int, option)

     def _get(self, section, conv, option):
         return conv(self.get(section, option))

-- 
Desarrollador freelance
http://www.arnau-sanchez.com

_______________________________________________
Lista de correo Python-es 
http://listas.aditel.org/listinfo/python-es
FAQ: http://listas.aditel.org/faqpyes
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.