import configparser
專注于為中小企業提供成都網站設計、成都網站制作服務,電腦端+手機端+微信端的三站合一,更高效的管理,為中小企業江城免費做網站提供優質的服務。我們立足成都,凝聚了一批互聯網行業人才,有力地推動了1000多家企業的穩健成長,幫助中小企業通過網站建設實現規模擴充和轉變。
config = configparser.ConfigParser()
#在DEFAULT節點下添加,類似字典的key和value
config["DEFAULT"] = {'ServerAliveInterval': '45', 'Compression': 'yes', 'CompressionLevel': '9'}
config['bitbucket.org'] = {"alex":33}
config['bitbucket.org']['User'] = 'hg'
config['topsecret.server.com'] = {}
topsecret = config['topsecret.server.com']
topsecret['Host Port'] = '50022' # mutates the parser
topsecret['ForwardX11'] = 'no' # same here
config['DEFAULT']['ForwardX11'] = 'yes' #在在DEFAULT節點下添加key為'ForwardX11,value為yes的數據
with open('example.ini', 'w') as configfile:
config.write(configfile)
#serveraliveinterval = 45
#compression = yes
#compressionlevel = 9
#forwardx11 = yes
#[bitbucket.org]
#alex = 33
#user = hg
#[topsecret.server.com]
#host port = 50022
#forwardx11 = no
import configparser
conf=configparser.ConfigParser()
conf.read("example.ini")
print(conf.sections())#打印節點(除了“DEFAULT”以外的節點)
print(conf["bitbucket.org"]["user"])
print(conf.defaults())#打印[DEFAULT]
#刪除后,創建新文件寫入
#sec = conf.remove_section('bitbucket.org')
#conf .write(open('exmple.cfg', "w"))
#刪除后,覆蓋原文件
#sec = conf.remove_section('bitbucket.org')
#conf .write(open('exmple.ini', "w"))
網站名稱:configparser模塊
網頁URL:http://vcdvsql.cn/article4/peidoe.html
成都網站建設公司_創新互聯,為您提供網站營銷、微信公眾號、網頁設計公司、微信小程序、ChatGPT、網站建設
聲明:本網站發布的內容(圖片、視頻和文字)以用戶投稿、用戶轉載內容為主,如果涉及侵權請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網站立場,如需處理請聯系客服。電話:028-86922220;郵箱:631063699@qq.com。內容未經允許不得轉載,或轉載時需注明來源: 創新互聯