Case Sensitive Section names configparser

Discussion in 'Python' started by RedBaron, Dec 8, 2010.

  1. RedBaron

    RedBaron Guest

    Is there any way by which configParser's get() function can be made
    case insensitive?
    RedBaron, Dec 8, 2010
    #1
    1. Advertising

  2. On 8 Dic, 11:32, RedBaron <> wrote:
    > Is there any way by which configParser's get() function can be made
    > case insensitive?


    If you don't care about the case of the config parameter values, you
    could pre-convert the input to
    configParser all in UPPER or lower letter with a file-like object like
    this (NOT TESTED):

    class AllUpperFile(object):
    def __init__(self, fname): self.fp = file(fname)
    def readline(self): return self.fp.readline().upper()

    and the use configParser.readfp method to feed the file-like object to
    the config parser

    myConfigparser.readfp( AllUpperFile("myconnfigfile.cfg")

    HTH

    Ciao
    ----
    FB
    Francesco Bochicchio, Dec 8, 2010
    #2
    1. Advertising

  3. RedBaron

    Jon Clements Guest

    On Dec 8, 10:32 am, RedBaron <> wrote:
    > Is there any way by which configParser's get() function can be made
    > case insensitive?


    I would probably subclass dict to create a string specific, case
    insensitive version, and supply it as the dict_type. See
    http://docs.python.org/library/configparser.html#ConfigParser.RawConfigParser

    That way your values would remain cased correctly, but lookups would
    be insensitive.

    hth

    Jon.
    Jon Clements, Dec 8, 2010
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Thomas Philips

    Case sensitive file names

    Thomas Philips, Feb 22, 2004, in forum: Python
    Replies:
    1
    Views:
    314
    Michel Claveau/Hamster
    Feb 22, 2004
  2. Tim Peters

    RE: Case sensitive file names

    Tim Peters, Feb 22, 2004, in forum: Python
    Replies:
    2
    Views:
    562
    Matt Gerrans
    Feb 23, 2004
  3. Delaney, Timothy C (Timothy)

    RE: Case sensitive file names

    Delaney, Timothy C (Timothy), Feb 23, 2004, in forum: Python
    Replies:
    2
    Views:
    289
    Peter Hansen
    Feb 23, 2004
  4. Replies:
    1
    Views:
    2,478
    Mark P
    Apr 6, 2007
  5. Xah Lee
    Replies:
    4
    Views:
    962
Loading...

Share This Page