[Baypiggies] configuration parser using python modules?

larryt at winfirst.com larryt at winfirst.com
Mon Jul 16 05:47:08 CEST 2012


+1 to YAML for reasons already mentioned.  Anything else is likely a detour along the path to enlightenment. 

-larry

---- Original message ----
>Date: Sun, 15 Jul 2012 09:16:53 -0700
>From: baypiggies-bounces+larryt=winfirst.com at python.org (on behalf of "Dmitry Kuzmenko" <morfizm at gmail.com>)
>Subject: Re: [Baypiggies] configuration parser using python modules?  
>To: "'Neil'" <neilkumar at gmail.com>,"'Brent Tubbs'" <brent.tubbs at gmail.com>
>Cc: baypiggies at python.org
>
>   I came across a nice combo solution yesterday:
>   little embedded json lists inside ConfigParser's
>   config (from  http://stackoverflow.com/a/9735884):
>
>    
>
>   [Foo]
>
>   fibs: [1,1,2,3,5,8,13]
>
>    
>
>   >>> json.loads(config.get("Foo","fibs"))
>
>   [1, 1, 2, 3, 5, 8, 13]
>
>    
>
>   Notice that you can actually span values over
>   multiple lines, useful for long strings, as long as
>   you add some tab/whitespace indent:
>
>    
>
>   [Foo]
>
>   fibs: [
>
>     "1",
>
>     "1",
>
>     "2",
>
>     "3",
>
>     "5",
>
>     "8",
>
>     "13"
>
>     ]
>
>    
>
>   The only annoyance is that you have to use double
>   quotes (json), and you can't put a comma after last
>   string.
>
>    
>
>   Dima.
>
>    
>
>    
>
>   -----Original Message-----
>   From: Neil [mailto:neilkumar at gmail.com]
>   Sent: Saturday, July 14, 2012 10:33 AM
>   To: Brent Tubbs
>   Cc: baypiggies at python.org
>   Subject: Re: [Baypiggies] configuration parser using
>   python modules?
>
>    
>
>   I like YAML too. I feel like JSON is only slightly
>   better than XML as for being human editable
>   (assuming its been pretty printed, otherwise a huge
>   JSON document can be worse off as far as readability
>   goes compared to XML) -- as it doesn't allow adding
>   comments (which I think is very important for
>   configuration files) and it barfs on things like a
>   trailing comma on a list or hash definitions.
>
>    
>
>   -neil
>
>    
>
>   On Sat, Jul 14, 2012 at 8:43 AM, Brent Tubbs
>   <brent.tubbs at gmail.com> wrote:
>
>   > My peeve against ConfigParser is that if you want
>   a list of things,
>
>   > you end up faking it with some incomplete-looking
>   syntax
>
>   > 
>
>   > [my_things]
>
>   > thing1 =
>
>   > thing2 =
>
>   > 
>
>   > That makes me sad.  (I'm looking at you, .hgrc.)
>
>   > 
>
>   > These days all my config files are YAML.  You get
>   all the lists and
>
>   > hashes that JSON can do, but you can leave out all
>   the quote marks and
>
>   > curly braces, which is a big plus for readability.
>
>   > 
>
>   > 
>
>   > On Fri, Jul 13, 2012 at 10:38 PM, Ian Zimmerman
>   <itz at buug.org> wrote:
>
>   >> 
>
>   >> 
>
>   >> David> app written in Python, some pub-sub stuff
>   written in JS on
>
>   >> David> Node
>
>   >> 
>
>   >> In this case, JSON seems like an obvious choice
>   for a config format
>
>   >> :-P
>
>   >> 
>
>   >> Personally, I try to just use
>   eval(read(open(CONFFILE))) whenever
>
>   >> remotely possible , guarded against surprises of
>   course.
>
>   >> 
>
>   >> The ConfigParser module is quite unpleasant IMO. 
>   Particularly
>
>   >> because the natural structure to hold such
>   information is either a
>
>   >> dictionary or an object with named fields, but
>   that's not what ConfigParser gives you.
>
>   >> 
>
>   >> --
>
>   >> Ian Zimmerman
>
>   >> gpg public key: 1024D/C6FF61AD
>
>   >> fingerprint: 66DC D68F 5C1B 4D71 2EE5  BD03 8A00
>   786C C6FF 61AD
>
>   >>
>   http://www.gravatar.com/avatar/c66875cda51109f76c6312f4d4743d1e.png
>
>   >> Rule 420: All persons more than eight miles high
>   to leave the court.
>
>   >> _______________________________________________
>
>   >> Baypiggies mailing list
>
>   >> Baypiggies at python.org
>
>   >> To change your subscription options or
>   unsubscribe:
>
>   >>
>   http://mail.python.org/mailman/listinfo/baypiggies
>
>   > 
>
>   > 
>
>   > 
>
>   > _______________________________________________
>
>   > Baypiggies mailing list
>
>   > Baypiggies at python.org
>
>   > To change your subscription options or
>   unsubscribe:
>
>   > http://mail.python.org/mailman/listinfo/baypiggies
>
>    
>________________
>_______________________________________________
>Baypiggies mailing list
>Baypiggies at python.org
>To change your subscription options or unsubscribe:
>http://mail.python.org/mailman/listinfo/baypiggies



More information about the Baypiggies mailing list