python 讀取配置文件

import configparser
import os
class ReadConfig:
    def __init__(self):
       self.config=configparser.ConfigParser()
    def read_config(self,section,key):
        path = os.path.split(os.path.realpath(__file__))[0] + '/application.config'
        self.config.read(path)
        return self.config.get(section, key)
if __name__ == '__main__':
   url= ReadConfig().read_config("user_info","user1")
   user=eval(url)
   print(user["user_name"])

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章