午夜剧场伦理_日本一道高清_国产又黄又硬_91黄色网战_女同久久另类69精品国产_妹妹的朋友在线

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

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

瀏覽:163日期: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)建一個新文件,并刪除 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') #刪除一個配置項(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

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

標(biāo)簽: Python 編程
相關(guān)文章:
主站蜘蛛池模板: 丁香婷婷成人 | 日韩在线观看中文字幕 | 久草在在线 | 免费观看亚洲 | 中文字幕www | 风间由美一区二区三区 | 校园春色第一页 | 亚洲精品视频一区二区三区 | 伊人网狼人 | 午夜免费精品 | 日韩精品久久久 | 夜夜干天天操 | 九九综合网 | 成人免费毛片视频 | 黄色免费网站在线看 | 国产精品久久欧美久久一区 | 亚洲视频在线免费观看 | 国产一级片免费看 | 中文字幕在线免费观看 | 18女人毛片 | 精品国产一区二区三区在线观看 | 日本天堂网站 | 99re免费视频 | 亚洲a在线视频 | 色大师av| 国产日韩视频在线观看 | 欧美成人一级 | 欧美中文字幕 | 久久麻豆精品 | 青青草97国产精品麻豆 | 国产免费一区二区三区 | 夜夜夜久久久 | 一区二区在线免费 | 亚洲国产精品激情在线观看 | 性感毛片 | 久草免费在线播放 | aaa亚洲精品 | 天堂网视频在线观看 | 亚洲最大av在线 | 毛片大全免费 | 黄色一级视频在线观看 |