[英]Python ConfigParser: how to work out options set in a specific section (rather than defaults)
[英]python configparser writing to defaults section
我在python中使用configparser模塊讀取和寫入一些.ini樣式文件。 我希望能夠創建和寫入DEFAULTS
部分,但是,似乎已對其進行了硬編碼,以不允許創建此類部分。
可能嗎? 甚至建議這樣做?
您不必創建DEFAULT節,它已經存在。 您可以立即在其中設置值。
config = ConfigParser.RawConfigParser()
config.set('DEFAULT', 'name2', 'value2')
with open('file.conf', 'wb') as cf:
config.write(cf)
如您所知,您在創建ConfigParser實例時設置為默認值的值也將寫入DEFAULT部分。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.