configparser模块

报错:ModuleNotFoundError: No module named 'ConfigParser'

解决:import configparser
           将c和p改成小写,方法名不变   python3没有ConfigParser模块

configparser用来处理配置文件的读/写。

从功能角度理解,一个配置可以理解为一个字典,在量化策略中,一个策略有多个参数,为每个参数赋值这件事就叫做配置。

从字典dict角度,一个字典变量可以分位三部分:1、字典名 2、键名 3、值

理解字典三部分,再去理解配置结构就容易了。相对应的,也可以分位:1、section名 2、option名(键) 3、值

举例:

配置文件格式:

 [] 里面内容为section,紧接着section 为类似于key-value 的options 的配置内容

读取配置

报错:configparser.InterpolationSyntaxError: '%' must be followed by '%' or '(', found: '%s-df@jw_1gq$1^8-j9+'

解决:将config = configparser.ConfigParser()

           换为:config = configparser.RawConfigParser()

原文地址:https://www.cnblogs.com/yu121/p/14749005.html