1. 程式人生 > >python讀取字典型別的文字檔案

python讀取字典型別的文字檔案

比如有個txt 文字檔案TestConf.ini,它的內容是一個字典:{"tester":"sterson","projectName":"baidu"}

def read_test_conf(confName):
    conf_path=get_aft_parent_path()+"\\Conf\\"+confName
    f=open(conf_path,"r")
    test_config=eval(f.read())
    f.close()
    return test_config
#讀取配置檔案
test_config=read_test_conf('TestConf.ini'
)

#讀取projectName

proName=test_config["projectName"]  #就是baidu