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

您的位置:首頁技術文章
文章詳情頁

Python configparser模塊操作代碼實例

瀏覽:171日期: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、刪除

# 刪除(創建一個新文件,并刪除 bitbucket.org)import configparserconfig = configparser.ConfigParser()config.sections()config.read(’example.ini’)rec = config.remove_section('bitbucket.org') # 刪除該項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') # 刪除該項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') #刪除一個配置項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

以上就是本文的全部內容,希望對大家的學習有所幫助,也希望大家多多支持好吧啦網。

標簽: Python 編程
相關文章:
主站蜘蛛池模板: 黄色成人免费视频 | 欧美日本一区二区三区 | 天堂综合网久久 | 香蕉视频在线看 | 日韩欧美视频在线免费观看 | 一级黄色片网址 | av在线资源观看 | 日本中文字幕免费在线观看 | 午夜视频一区二区 | 91激情四射 | av免费福利 | 五月在线 | 国产视频一区在线 | 尤物最新网址 | 激情第一页 | 国产噜噜噜| 午夜爽爽爽男女免费观看 | 四虎影院在线 | 狠狠2019| av成人亚洲| 伊人国产视频 | 黑人巨大精品欧美一区二区免费 | 国产一级免费 | 久草超碰 | 在线观看亚洲成人 | 亚洲最大激情网 | 日韩三级av| japanese在线视频 | 亚洲欧美v | 久久精品蜜桃 | 亚洲无线观看 | 国产中文字幕第一页 | 亚色在线观看 | 欧美日韩午夜 | 日本特黄特色aaa大片免费 | 亚日韩在线| 成人高清在线观看 | 日韩射吧| 成人免费在线播放 | 欧美精品一区二区在线观看 | 五月婷在线视频 |