Python 读取写入配置文件 —— ConfigParser

 

  Python 读取写入配置文件很方便,可使用内置的 configparser 模块;可查看源码,如博主本机地址: “C:/python27/lib/configparser.py”

Configuration file parser.
 
A setup file consists of sections, lead by a "[section]" header,
and followed by "name: value" entries, with continuations and such in
the style of RFC 822.

  该模块支持读取类似如上格式的配置文件,如 windows 下的 .conf 及 .ini 文件等。

  本章节使用如下的配置文件作为示例,可在 D 盘下新建 Pyhton_config 文件夹,创建两个文件 test.config  及 test.ini  内容及示例截图如下:

1 [db]
2 db_port = 3306
3 db_user = root
4 db_host = 127.0.0.1
5 db_pass = xgmtest
6 
7 [concurrent]
8 processor = 20
9 thread = 10
View Code

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2021-07-06
  • 2022-12-23
  • 2021-08-24
  • 2022-02-13
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-09-24
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案