|
From: Nicolas M. <nic...@le...> - 2011-06-20 15:29:46
|
I just find the answer by reading this : http://www.voidspace.org.uk/python/articles/configobj_for_data_persistence.shtml#creating-a-configspec So here is what I did : for sub in (keys for keys in config['opghl'] if isinstance(config['opghl'][keys],dict)): print sub Then it prints me : db_prod db_prod_2 (See my first mail below) But I was wondering if you can't implement a method to do it more easily or maybe to document it better in the official doc : http://www.voidspace.org.uk/python/configobj.html Is this the better way to achieve mu goal? Or there is a more pythonic way? Regards, sylock On 06/20/2011 04:49 PM, Nicolas Michel wrote: > Hello, > > I have a problem understanding subsections with configobj. > > Here is the structure of my config file : > > [__main_section_1__] > key1 = string > key2 = string > key3 = string > [[__subsection_1__]] > sub_key_1 = string > sub_key_2 = string > > (So there is an unlimited number of main section in which I have some > subsections ; at least one subsection by main section) > > What I need to do is a loop on each subsection to do some job. I can't > do it (I'm new with Python so please excuse me if my question seems silly). > > something like : > for subsections in main_section: > my_code > > Here is a structure sample of my current config file : > > ConfigObj({'opghl': {'acc_user': 'openerp', 'prod_user': 'openerp', > 'acc_host': 'ghl-dev.lan.pcsol.be', 'db_prod': {'prod_db_name': 'ghl', > 'acc_db_name': 'ghl'}, 'db_prod_2': {'prod_db_name': 'ghl2', > 'acc_db_name': 'ghl2'}}, 'test': {'acc_user': 'openerp-test', > 'prod_user': 'openerp-test', 'acc_host': 'test-dev.lan.pcsol.be', > 'db_prod-test': {'prod_db_name': 'ghl-test', 'acc_db_name': 'ghl-test'}, > 'db_prod_2-test': {'prod_db_name': 'ghl2-test', 'acc_db_name': > 'ghl2-test'}}}) > > ==> I would want to list all the subsection of opghl or test. In that > case it would be > - for opghl : db_prod and db_prod_2 > - for test : db_prod-test, db_prod_2-test > > Thank you a lot for your help! > sylock > > ------------------------------------------------------------------------------ > EditLive Enterprise is the world's most technically advanced content > authoring tool. Experience the power of Track Changes, Inline Image > Editing and ensure content is compliant with Accessibility Checking. > http://p.sf.net/sfu/ephox-dev2dev > _______________________________________________ > Configobj-develop mailing list > Con...@li... > https://lists.sourceforge.net/lists/listinfo/configobj-develop |