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