1.下載安裝 configparser 第三方模塊
pip install configparser
2.讀取組態檔
#組態檔內容如下 """ "D:/config/config.ini" """ [stu_name] name = "zhangsan" [stu_age] name = "zhangsan" [stu_sex] sex = "boy"
#讀取操作如下 import configparser #獲取實體物件conf conf = configparser.ConfigParser() #進行讀取操作 read(filename) conf.read("D:/config/config.ini") #獲取value值 get(section,option) value = https://www.cnblogs.com/ZhengYing0813/p/conf.get("stu_name","name") print(value) #獲取所有的節點 print(conf.sections()) #執行結果如下 "zhangsan" ['stu_name', 'stu_age', 'stu_sex']
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/179642.html
標籤:Python
上一篇:Python_串列方法
