久久福利_99r_国产日韩在线视频_直接看av的网站_中文欧美日韩_久久一

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

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

瀏覽:90日期: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)文章:
主站蜘蛛池模板: 成人在线免费视频 | 一本大道综合伊人精品热热 | 热久久这里只有精品 | 亚洲视频 欧美视频 | 婷婷五月色综合 | 亚洲欧美精品 | 免费观看视频www | 亚洲国产精品久久 | 日韩在线不卡 | 成年视频在线观看福利资源 | 婷婷综合五月 | 高清av网址 | 日本一区二区不卡视频 | www.888www看片| 日本久草| 狠狠撸在线 | 最新日韩一区 | 欧美日韩综合在线 | 亚洲网在线 | 精品免费国产一区二区三区四区 | 午夜看看| 欧美国产日韩在线观看 | 亚洲天天干 | 久久久国产视频 | 国产婷婷综合 | 亚洲国产一区视频 | 在线一级片 | 国产在线精品一区二区 | 色黄网站 | 亚洲国产精品一区二区三区 | 国产精品久久久久久婷婷天堂 | 日韩中文在线 | 日韩一区二区三区精品 | 激情欧美一区二区三区中文字幕 | 欧美日日 | 国产日韩一级片 | 亚洲男人天堂网 | 日韩一二三区 | 亚洲精品乱码久久久久久蜜桃91 | 久久草草影视免费网 | 色综合天天综合网国产成人网 |