|
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
|