|
From: Michael F. <fuz...@vo...> - 2009-01-12 14:34:27
|
Nicholas Bayle wrote: > Hello- > > I have a need to read an ini file (that I have no control over) that > uses ; as the comment marker. > > I found the following with respect to that: > http://sourceforge.net/mailarchive/message.php?msg_id=46F666FC.8080500%40voidspace.org.uk > > > You should be able to switch over the dividers and comment markers > that > > ConfigObj allows by changing the regular expressions it uses for > parsing. > > > > The regexes are class attributes of the ConfigObj class. > Unfortunately > > you probably need to modify all of them. This should be quite easy > though. > > But, as I'm new to all of this, I have no idea how to set class > attributes or what the correct regular expression(s) would be. Can > anyone provide examples? > Hmmm... try swapping the hashes (#) in the regexes for semicolons. > Also, this particular ini file lists duplicate "keyword" names as a > way to specify multiple parameters, like so: > > TrustedCACert=/etc/CA/admin.pem > TrustedCACert=/etc/CA/client.pem > > This causes ConfigObj to barf--which is fine, because I don't need to > read these values, I would just like to ignore the error and move on. > Is this possible? > This is actually the default behavior - but you have to catch the exception to access the successfully parsed values. try: config = ConfigObj(filename) except Exception, e: config = e.config Michael Foord > > Thanks for any help and excuse my voluminous ignorance... > Nick > > ------------------------------------------------------------------------------ > Check out the new SourceForge.net Marketplace. > It is the best place to buy or sell services for > just about anything Open Source. > http://p.sf.net/sfu/Xq1LFB > _______________________________________________ > Configobj-develop mailing list > Con...@li... > https://lists.sourceforge.net/lists/listinfo/configobj-develop > -- http://www.ironpythoninaction.com/ http://www.voidspace.org.uk/blog |