1. 程式人生 > >python 讀取 配置文件

python 讀取 配置文件

python 讀取 配置文件

讀取方法:
def get(section,option):
    cp = ConfigParser.SafeConfigParser()
    cp.read(os.path.split(os.path.realpath(__file__))[] + )
    cp.get(section,option)
    
    
配置文件:
#mongodb數據庫信息
[mongodb]
host=192.168.1.102
port=27017
#mysql數據庫參數
[mysqldb]
host = 192.168.1.93
port=3306
user=root
passwd=123456
db=zhuzhuxia
charset=utf8
執行
get("mysqldb","host")

python 讀取 配置文件