国产成人精品久久免费动漫-国产成人精品天堂-国产成人精品区在线观看-国产成人精品日本-a级毛片无码免费真人-a级毛片毛片免费观看久潮喷

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

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

瀏覽:98日期: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)文章:
主站蜘蛛池模板: 毛片在线免费视频 | 永久免费毛片在线播放 | 国产视频高清在线 | 中文字幕一区二区三区精彩视频 | 日本一级毛片片在线播放 | 97精品国产91久久久久久久 | 一级成人黄色片 | 亚洲欧洲视频在线 | 欧美精品亚洲精品日韩专区 | 亚洲午夜成激人情在线影院 | 老妇综合久久香蕉蜜桃 | 国产在线观看一区精品 | 黄色美女毛片 | 欧美精品99久久久久久人 | 亚洲国产福利精品一区二区 | 91国内精品视频 | 91久久亚洲精品一区二区 | 美女的让男人桶到爽软件 | 久久久999国产精品 久久久99精品免费观看 | 免费人成综合在线视频 | 亚洲一区免费在线 | 在线视频一区二区 | 国产亚洲高清在线精品不卡 | 97香蕉久久夜色精品国产 | 亚洲一区二区三区成人 | 成人高清在线观看播放 | 久久久久久久国产 | 精品久久成人免费第三区 | 国产高清精品自在线看 | 九九夜色| 在线播放国产一区二区三区 | 欧美激情亚洲色图 | 无码免费一区二区三区免费播放 | 亚洲成人黄色在线观看 | 国产高清美女一级a毛片久久w | 生活片一级播放免费 | 美国一级片免费看 | 国产成人亚洲精品影院 | 欧美中文在线 | 欧美性活一级视频 | 综合欧美一区二区三区 |