最近在在看別人代碼的時候發現有人用了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,以及數字