|
From: Arash A. <aza...@gm...> - 2011-11-21 21:09:27
|
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 ?
Thanks ,
Arash.
|
|
From: L. C. <l.c...@gm...> - 2011-11-21 21:23:19
|
On Mon, Nov 21, 2011 at 4:09 PM, Arash Azarmi <aza...@gm...> 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 ?
>
> 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 list
> Con...@li...
> https://lists.sourceforge.net/lists/listinfo/configobj-develop
>
>
Hello,
If I recall correctly, .scalars is an ordered list of the items in the
ConfigObj. See: http://www.voidspace.org.uk/python/configobj.html#sections
This exists for both Sections and ConfigObj, again if I recall correctly.
-Leonardo
|
|
From: Michael F. <fuz...@vo...> - 2011-11-21 21:29:34
|
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 list
> Con...@li...
> https://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
|
|
From: Arash A. <aza...@gm...> - 2011-11-22 01:57:10
|
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
>
>
|
|
From: L. C. <l.c...@gm...> - 2011-11-22 04:40:14
|
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
>
>
|
|
From: Arash A. <aza...@gm...> - 2011-11-22 06:26:42
|
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 ?
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
>
>
|
|
From: Michael F. <fuz...@vo...> - 2011-11-22 11:08:21
|
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...
> <mailto: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...
> <mailto:aza...@gm...>> wrote:
>
> As far as I try , it does not preserve , here is a sample code :
>
> *config = configobj.ConfigObj()*
> *config.filename = "file.name <http://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... <mailto: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 list
>> Con...@li... <mailto:Con...@li...>
>> https://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 blessinghttp://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...
> <mailto: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...
> <mailto: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
--
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
|
|
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 > > |
|
From: Michael F. <fuz...@vo...> - 2011-11-22 22:50:04
|
On 22/11/2011 21:02, Arash Azarmi wrote: > Thanks for clarification.It could be nice if it had that feature. Do > you have any suggestions ? > Not really, sorry. Because of the ConfigObj syntax it's not possible for the order *between* sections and scalars to be preserved. You'll have to wrap ConfigObj and store the information yourself as an extra entry I think. All the best, Michael > Best , > Arash. > > On Tue, Nov 22, 2011 at 3:08 AM, Michael Foord > <fuz...@vo... <mailto: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... >> <mailto: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... <mailto:aza...@gm...>> wrote: >> >> As far as I try , it does not preserve , here is a sample >> code : >> >> *config = configobj.ConfigObj()* >> *config.filename = "file.name <http://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... >> <mailto: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 list >>> Con...@li... <mailto:Con...@li...> >>> https://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 blessinghttp://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... >> <mailto: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... >> <mailto: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... <mailto:Con...@li...> >> https://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 blessinghttp://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 -- 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 |