|
From: Michael F. <fuz...@vo...> - 2009-06-08 11:01:55
|
Scott Flynn wrote:
> That works for me. Thanks. One other thing, is it possible to make the
> keys in a ConfigObj case insensitive?
Not directly I'm afraid. You could fetch all the keys and do a case
insensitive match though:
def get_value_case_insensitive(key, section):
keys = dict([(entry.lower(), entry) for entry in section.keys()])
real_key = keys[key.lower()] # will raise KeyError if key is not found
return section[real_key]
config = ConfigObj(filename)
section = get_value_case_insensitive('my_Timer', config) # fetch the
section case-insensitively
value = get_value_case_insensitive('some_key', section) # fetch the
required key case-insensitively
HTH
Michael
>
> On Sun, Jun 7, 2009 at 3:29 PM, Michael Foord
> <fuz...@vo... <mailto:fuz...@vo...>> wrote:
>
> Scott Flynn wrote:
> > Does anyone have a vim syntax file for Config Object?
> >
>
> Not me.
>
> > Second, I want to know if there's a way to have defaults for
> sections
> > where the name is only partially known.
> >
> > For instance:
> >
> > [widget_MyTimer]
> > type="timer"
> > interval=500
> > expression=doAction()
> >
> > And it may also have a precision option but this widget doesn't need
> > it since the expression's not mathematical. This precision is
> supposed
> > to be 1000 if missing, not that it matters in this case, meaning
> > precision limited by Python's natural floating point precision. Can
> > that be done on Config Object's side?
>
> Not *really* sure what you want here. One way to do it would be to use
> the get method where you can supply a default if the key is missing:
>
> config = ConfigObj(filename)
> timer = config['widget_MyTimer']
> precision = timer.get('precision', '1000')
>
> All the best,
>
>
> Michael
>
> >
> ------------------------------------------------------------------------
> >
> >
> ------------------------------------------------------------------------------
> > OpenSolaris 2009.06 is a cutting edge operating system for
> enterprises
> > looking to deploy the next generation of Solaris that includes
> the latest
> > innovations from Sun and the OpenSource community. Download a
> copy and
> > enjoy capabilities such as Networking, Storage and Virtualization.
> > Go to: http://p.sf.net/sfu/opensolaris-get
> >
> ------------------------------------------------------------------------
> >
> > _______________________________________________
> > Configobj-develop mailing list
> > Con...@li...
> <mailto:Con...@li...>
> > https://lists.sourceforge.net/lists/listinfo/configobj-develop
> >
>
>
> --
> http://www.ironpythoninaction.com/
> http://www.voidspace.org.uk/blog
>
>
>
> ------------------------------------------------------------------------------
> OpenSolaris 2009.06 is a cutting edge operating system for enterprises
> looking to deploy the next generation of Solaris that includes the
> latest
> innovations from Sun and the OpenSource community. Download a copy and
> enjoy capabilities such as Networking, Storage and Virtualization.
> Go to: http://p.sf.net/sfu/opensolaris-get
> _______________________________________________
> Configobj-develop mailing list
> Con...@li...
> <mailto:Con...@li...>
> https://lists.sourceforge.net/lists/listinfo/configobj-develop
>
>
> ------------------------------------------------------------------------
>
> ------------------------------------------------------------------------------
> OpenSolaris 2009.06 is a cutting edge operating system for enterprises
> looking to deploy the next generation of Solaris that includes the latest
> innovations from Sun and the OpenSource community. Download a copy and
> enjoy capabilities such as Networking, Storage and Virtualization.
> Go to: http://p.sf.net/sfu/opensolaris-get
> ------------------------------------------------------------------------
>
> _______________________________________________
> Configobj-develop mailing list
> Con...@li...
> https://lists.sourceforge.net/lists/listinfo/configobj-develop
>
--
http://www.ironpythoninaction.com/
http://www.voidspace.org.uk/blog
|