亚洲精品久久久中文字幕-亚洲精品久久片久久-亚洲精品久久青草-亚洲精品久久婷婷爱久久婷婷-亚洲精品久久午夜香蕉

您的位置:首頁(yè)技術(shù)文章
文章詳情頁(yè)

Python configparser模塊操作代碼實(shí)例

瀏覽:70日期:2022-07-22 09:04:50

1、生成配置文件

’’’ 生成配置文件’’’import configparserconfig = configparser.ConfigParser()# 初始化賦值config['DEFAULT'] = {’ServerAliveInterval’: ’45’, ’Compression’: ’yes’, ’CompressionLevel’: ’9’}# 追加config[’DEFAULT’][’ForwardX11’] = ’yes’config[’bitbucket.org’] = {}config[’bitbucket.org’][’User’] = ’hg’config[’topsecret.server.com’] = {}topsecret = config[’topsecret.server.com’]topsecret[’Host Port’] = ’50022’ # mutates the parsertopsecret[’ForwardX11’] = ’no’ # same herewith open(’example.ini’, ’w’) as configfile: config.write(configfile)

2、讀取配置文件

# 讀import configparserconfig = configparser.ConfigParser()config.sections()config.read(’example.ini’)# {’serveraliveinterval’: ’45’, ’compression’: ’yes’, ’compressionlevel’: ’9’, ’forwardx11’: ’yes’}print(config.defaults())# hgprint(config[’bitbucket.org’]['User'])# 50022print(config['topsecret.server.com']['host port'])

3、刪除

# 刪除(創(chuàng)建一個(gè)新文件,并刪除 bitbucket.org)import configparserconfig = configparser.ConfigParser()config.sections()config.read(’example.ini’)rec = config.remove_section('bitbucket.org') # 刪除該項(xiàng)config.write(open('example.cfg','w'))

生成新文件 example.cfg

DEFAULT]serveraliveinterval = 45compression = yescompressionlevel = 9forwardx11 = yestopsecret.server.com]host port = 50022forwardx11 = no

刪除,并覆蓋原文件

# 刪除(刪除 bitbucket.org)import configparserconfig = configparser.ConfigParser()config.sections()config.read(’example.ini’)rec = config.remove_section('bitbucket.org') # 刪除該項(xiàng)config.write(open('example.ini','w'))

4、修改

import configparserconfig = configparser.ConfigParser()config.read(’example.ini’) #讀文件config.add_section(’yuan’) #添加sectionconfig.remove_section(’bitbucket.org’) #刪除sectionconfig.remove_option(’topsecret.server.com’,'forwardx11') #刪除一個(gè)配置項(xiàng)config.set(’topsecret.server.com’,’k1’,’11111’)config.set(’yuan’,’k2’,’22222’)with open(’new2.ini’,’w’) as f: config.write(f)

生成新文件 new2.ini

[DEFAULT]serveraliveinterval = 45compression = yescompressionlevel = 9forwardx11 = yes[topsecret.server.com]host port = 50022k1 = 11111[yuan]k2 = 22222

以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持好吧啦網(wǎng)。

標(biāo)簽: Python 編程
相關(guān)文章:
主站蜘蛛池模板: 久久草草 | 看黄视频免费 | 国产精品xxxav免费视频 | 欧美精品一区在线看 | 国产女人综合久久精品视 | 亚洲免费观看在线视频 | 黄色成人免费观看 | 黄色一级免费观看 | 国产精品国产精品国产专区不卡 | 毛片网站大全 | 亚洲视频欧美视频 | 国产精品福利在线播放 | 黄色一级大片免费看 | 中文字幕一级片 | 午夜tv影院| 国产免费高清mv视频在线观看 | 亚洲免费国产 | 91国内精品久久久久怡红院 | 综合在线视频精品专区 | 91porn国产在线观看 | 狠狠色噜噜狠狠狠狠狠色综合久久 | 欧美一级网址 | 欧美一级视频精品观看 | 成人午夜精品久久久久久久小说 | 国产精品高清一区二区三区不卡 | 黄色毛片大全 | 污污网站在线 | 国产成人涩涩涩视频在线观看免费 | 性毛片| 久久久精品在线观看 | 黄色一级片美国 | 欧美日韩亚洲二区在线 | 日本精品久久久久中文字幕8 | 日本精品一区二区三区在线 | 国产在线资源站 | 黑人巨大videosjapan高清 黑人巨大vsさとう遥希 | 国产乱码精品一区二区三区中 | 色涩在线| 谁有毛片网址 | 日韩精品区 | 韩国xxxx色视频免费 |