最近在在看别人代码的时候发现有人用了config这个库来保存一些超参数,超参数的设置在深度学习中是非常重要了。一般的config 库可以直接通过pip install config 安装
废话不多说,直接上一个官网上的简单样例;
先创建个配置文件simple.cfg,内容如下:
# The message to print (this is a comment) message: 'Hello, world!'
#符号是注释作用
每行用 : 符号作为分隔符
from config import Config # You can pass any file-like object; if it has a name attribute, # that name is used when file format error messages are printed f = file('simple.cfg') cfg = Config(f) print cfg.message
值的话一般是支持字符串,bool行的True和False,以及数字