|
From: Arash A. <aza...@gm...> - 2011-11-22 21:02:39
|
Thanks for clarification.It could be nice if it had that feature. Do you have any suggestions ? Best , Arash. On Tue, Nov 22, 2011 at 3:08 AM, Michael Foord <fuz...@vo...>wrote: > On 22/11/2011 06:26, Arash Azarmi wrote: > > Yes but it only preserves the order for scalars(or sections) .Cant keep > both at same. > > If you insert scalar *a* within section *A* ,then insert section *B *in > section A , and then insert scalar *b , *and then section* C *the order I > like to see is* : a , B , b ,C* > But with scalars you get* a,b , * > and with sections you get* B,C .* > * > * > Is there away you get both ? > > > That can't work with configobj. Think about this example: > > c = ConfigObj() > c['one'] = 'one' > c['section'] = {} > c['two'] = 'two' > > When ConfigObj writes out the file it does this: > > >>> for line in c.write(): > ... print line > ... > one = one > two = two > [section] > > You seem to want it to do this: > one = one > [section] > two = two > > The problem is that the key 'two' is now *inside* 'section' - it's in the > wrong place and when reading the file back in it would do the wrong thing. > Scalars *have* to be written out before sections. > > All the best, > > Michael > > Thanks , > Arash. > > On Mon, Nov 21, 2011 at 8:40 PM, L. Canessa <l.c...@gm...> wrote: > >> Did you read the documentation? >> >> It's supposed to be: >> >> *for i in config['procedure'].scalars* >> * >> * >> If I recall correctly. >> >> -Leonardo >> >> >> >> On Mon, Nov 21, 2011 at 8:56 PM, Arash Azarmi <aza...@gm...>wrote: >> >>> As far as I try , it does not preserve , here is a sample code : >>> >>> *config = configobj.ConfigObj()* >>> *config.filename = "file.name"* >>> *procedure={}* >>> *loop={'sweep':[],'contents':OrderedDict()}* >>> *config['procedure']=procedure* >>> *config['procedure']['var_1']=1* >>> *config['procedure']['var_2']=1* >>> *config['procedure']['loop.1']=loop* >>> *config['procedure']['var_3']=1* >>> *config.write()* >>> * >>> * >>> *for i in config['procedure'] :* >>> * print i,'=',str(config['procedure'][i])* >>> * if i.find('loop')==0:* >>> * for j in config['procedure'][i]:* >>> * print j,'=',str(config['procedure'][i])* >>> * >>> * >>> Output is : >>> * >>> * >>> * >>> var_1 = 1 >>> var_2 = 1 >>> var_3 = 1 <--------- This is out of order.It should be printed last of >>> all. >>> loop.1 = {'sweep': [], 'contents': {}} >>> sweep = {'sweep': [], 'contents': {}} >>> contents = {'sweep': [], 'contents': {}} >>> * >>> >>> On Mon, Nov 21, 2011 at 1:29 PM, Michael Foord < >>> fuz...@vo...> wrote: >>> >>>> On 21/11/2011 21:09, Arash Azarmi wrote: >>>> >>>> Hi all , >>>> I am using configObj to store inputs from user.In my case, the sequence >>>> matters so I can't let the configObj don't store sequence order.Both >>>> Section and ConfigObj are implemented as ordinary dictionary {} . I tried >>>> to change that to OrderedDict (from collections) but apparently it's not >>>> working again.Has anybody a solution for this ? >>>> >>>> >>>> ConfigObj does store (and preserve when reading / writing) order. >>>> >>>> See the documentation on the "sections" and "scalars" attributes of >>>> sections: >>>> >>>> >>>> http://www.voidspace.org.uk/python/configobj.html#section-attributes >>>> >>>> These attributes are normal lists, representing the order that members, >>>> single values and subsections appear in the section. The order will either >>>> be the order of the original config file, or the order that you added >>>> members. >>>> >>>> The order of members in this lists is the order that write creates in >>>> the config file. The scalars list is output before the sections list. >>>> >>>> Adding or removing members also alters these lists. You can manipulate >>>> the lists directly to alter the order of members. >>>> >>>> All the best, >>>> >>>> Michael Foord >>>> >>>> >>>> Thanks , >>>> Arash. >>>> >>>> >>>> ------------------------------------------------------------------------------ >>>> All the data continuously generated in your IT infrastructure >>>> contains a definitive record of customers, application performance, >>>> security threats, fraudulent activity, and more. Splunk takes this >>>> data and makes sense of it. IT sense. And common sense.http://p.sf.net/sfu/splunk-novd2d >>>> >>>> >>>> >>>> _______________________________________________ >>>> Configobj-develop mailing lis...@li...://lists.sourceforge.net/lists/listinfo/configobj-develop >>>> >>>> >>>> >>>> -- http://www.voidspace.org.uk/ >>>> >>>> May you do good and not evil >>>> May you find forgiveness for yourself and forgive others >>>> May you share freely, never taking more than you give. >>>> -- the sqlite blessing http://www.sqlite.org/different.html >>>> >>>> >>> >>> >>> ------------------------------------------------------------------------------ >>> All the data continuously generated in your IT infrastructure >>> contains a definitive record of customers, application performance, >>> security threats, fraudulent activity, and more. Splunk takes this >>> data and makes sense of it. IT sense. And common sense. >>> http://p.sf.net/sfu/splunk-novd2d >>> _______________________________________________ >>> Configobj-develop mailing list >>> Con...@li... >>> https://lists.sourceforge.net/lists/listinfo/configobj-develop >>> >>> >> >> ------------------------------------------------------------------------------ >> All the data continuously generated in your IT infrastructure >> contains a definitive record of customers, application performance, >> security threats, fraudulent activity, and more. Splunk takes this >> data and makes sense of it. IT sense. And common sense. >> http://p.sf.net/sfu/splunk-novd2d >> _______________________________________________ >> Configobj-develop mailing list >> Con...@li... >> https://lists.sourceforge.net/lists/listinfo/configobj-develop >> >> > > > ------------------------------------------------------------------------------ > All the data continuously generated in your IT infrastructure > contains a definitive record of customers, application performance, > security threats, fraudulent activity, and more. Splunk takes this > data and makes sense of it. IT sense. And common sense.http://p.sf.net/sfu/splunk-novd2d > > > > _______________________________________________ > Configobj-develop mailing lis...@li...://lists.sourceforge.net/lists/listinfo/configobj-develop > > > > -- http://www.voidspace.org.uk/ > > May you do good and not evil > May you find forgiveness for yourself and forgive others > May you share freely, never taking more than you give. > -- the sqlite blessing http://www.sqlite.org/different.html > > |