- 论坛徽章:
- 0
|
取自python 标准库附带示例代码,并且做了一些修改:
- import ConfigParser
- import sys
- config = ConfigParser.ConfigParser()# set a number of parameters
- config.add_section("book")
- config.set("book", "title", "the python standard library")
- config.set("book", "author", "fredrik lundh")
- config.add_section("ematter")
- config.set("ematter", "pages", 250)# write to screen
- config.add_section("ematter123")
- config.set("ematter123", "pages123", 250)# write to screen
- config.write(sys.stdout)
-
复制代码
打印的顺序是:
- [book]
- author = fredrik lundh
- title = the python standard library
- [ematter123]
- pages123 = 250
- [ematter]
- pages = 250
复制代码
但是在Python自带的手册中,却是这么说的:
- # When adding sections or items, add them in the reverse order of
- # how you want them to be displayed in the actual file.
- # In addition, please note that using RawConfigParser's and the raw
- # mode of ConfigParser's respective set functions, you can assign
- # non-string values to keys internally, but will receive an error
- # when attempting to write to a file or when you get it in non-raw
- # mode. SafeConfigParser does not allow such assignments to take place.
复制代码
也就是说,打印的时候会按照添加的逆序进行打印,但是上面的结果发现根本不是这么回事. |
|