最近2018中文字幕在日韩欧美国产成人片_国产日韩精品一区二区在线_在线观看成年美女黄网色视频_国产精品一区三区五区_国产精彩刺激乱对白_看黄色黄大色黄片免费_人人超碰自拍cao_国产高清av在线_亚洲精品电影av_日韩美女尤物视频网站

RELATEED CONSULTING
相關(guān)咨詢
選擇下列產(chǎn)品馬上在線溝通
服務(wù)時間:8:30-17:00
你可能遇到了下面的問題
關(guān)閉右側(cè)工具欄

新聞中心

這里有您想知道的互聯(lián)網(wǎng)營銷解決方案
怎么在Python中使用configparser庫讀取配置文件-創(chuàng)新互聯(lián)

怎么在Python中使用configparser庫讀取配置文件?針對這個問題,這篇文章詳細(xì)介紹了相對應(yīng)的分析和解答,希望可以幫助更多想解決這個問題的小伙伴找到更簡單易行的方法。

網(wǎng)站的建設(shè)創(chuàng)新互聯(lián)建站專注網(wǎng)站定制,經(jīng)驗豐富,不做模板,主營網(wǎng)站定制開發(fā).小程序定制開發(fā),H5頁面制作!給你煥然一新的設(shè)計體驗!已為成都建筑動畫等企業(yè)提供專業(yè)服務(wù)。
from configparser import ConfigParser

class DoConfig:
  def __init__(self,filepath,encoding='utf-8'):
    self.cf = ConfigParser()
    self.cf.read(filepath,encoding)

  #獲取所有的section
  def get_sections(self):
    return self.cf.sections()

  #獲取某一section下的所有option
  def get_option(self,section):
    return self.cf.options(section)

  #獲取section、option下的某一項值-str值
  def get_strValue(self,section,option):
    return self.cf.get(section,option)

  # 獲取section、option下的某一項值-int值
  def get_intValue(self, section, option):
    return self.cf.getint(section, option)

  # 獲取section、option下的某一項值-float值
  def get_floatValue(self, section, option):
    return self.cf.getfloat(section, option)

  # 獲取section、option下的某一項值-bool值
  def get_boolValue(self, section, option):
    return self.cf.getboolean(section, option)

  def setdata(self,section,option,value):
    return self.cf.set(section,option,value)

if __name__ == '__main__':
  cf = DoConfig('demo.conf')
  res = cf.get_sections()
  print(res)
  res = cf.get_option('db')
  print(res)
  res = cf.get_strValue('db','db_name')
  print(res)
  res = cf.get_intValue('db','db_port')
  print(res)
  res = cf.get_floatValue('user_info','salary')
  print(res)
  res = cf.get_boolValue('db','is')
  print(res)

  cf.setdata('db','db_port','3306')
  res = cf.get_strValue('db', 'db_port')
  print(res)

關(guān)于怎么在Python中使用configparser庫讀取配置文件問題的解答就分享到這里了,希望以上內(nèi)容可以對大家有一定的幫助,如果你還有很多疑惑沒有解開,可以關(guān)注創(chuàng)新互聯(lián)成都網(wǎng)站設(shè)計公司行業(yè)資訊頻道了解更多相關(guān)知識。

另外有需要云服務(wù)器可以了解下創(chuàng)新互聯(lián)scvps.cn,海內(nèi)外云服務(wù)器15元起步,三天無理由+7*72小時售后在線,公司持有idc許可證,提供“云服務(wù)器、裸金屬服務(wù)器、高防服務(wù)器、香港服務(wù)器、美國服務(wù)器、虛擬主機(jī)、免備案服務(wù)器”等云主機(jī)租用服務(wù)以及企業(yè)上云的綜合解決方案,具有“安全穩(wěn)定、簡單易用、服務(wù)可用性高、性價比高”等特點與優(yōu)勢,專為企業(yè)上云打造定制,能夠滿足用戶豐富、多元化的應(yīng)用場景需求。


本文名稱:怎么在Python中使用configparser庫讀取配置文件-創(chuàng)新互聯(lián)
當(dāng)前地址:http://fisionsoft.com.cn/article/dgisjh.html