ConfigParser - setting the order of options in a section

S.Ramaswamy srsy70 at yahoo.com
Mon Jan 19 10:24:50 EST 2004


I am trying unsuccessfully to set the order of options using  the
set(section,option,value) method ( Python 2.2.2) and writing to a
file. But the options always appear in a random order. Before each
option I am writing a comment line using set(section,"#",value) - a
one line explanation for the option that follows - but the comments
get re-ordered randomly.

------------------------------------------------------------------------------------
cfg.add_section("COOL")
cfg.set("COOL","#","This is option A001")
cfg.set("COOL","A001","1")
cfg.set("COOL","#","This is option B001")
cfg.set("COOL","B001","2")
cfg.set("COOL","#","This is option C001")
cfg.set("COOL","C001","3")
cfg.write(file)
-------------------------------------------------------------------------------------


The comments for the options get jumbled up - I want them to be
written before the option=value line. Instead the comments for options
A001,B001,C001 all get ordered randomly.

Any help  in getting the sections to be written in order will be
appreciated.

srsy

-



More information about the Python-list mailing list