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

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

Python configparser模塊操作代碼實例

瀏覽:67日期: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') # 刪除該項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

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

標簽: Python 編程
相關(guān)文章:
主站蜘蛛池模板: 九草在线播放 | 国产精品黄在线观看观看 | 国产精品怡红院在线观看 | 波多野结衣视频在线观看地址免费 | 国产在线精品二区韩国演艺界 | 99er精品 | 一级无毛片 | 久草在线视频资源站 | 欧美同性videos在线可播放 | 碰碰碰精品视频在线观看 | 久久国产一区二区三区 | 国产综合在线观看 | 尤物蜜芽福利国产污在线观看 | 国产成年人 | 色本道 | 国产精品久久久影院 | 456亚洲视频 | 美国全免费特一级毛片 | 免费福利入口在线观看 | 久久久久久综合一区中文字幕 | 国产一级黄毛片 | 三级黄色毛片视频 | 国产性大片黄在线观看在线放 | 日本久久久久久 | 亚洲成人欧美 | 亚洲精品区 | 国产精品视频视频久久 | 国产最猛性xxxxxx69交 | 二区国产| 欧美高清一级 | 在线黄网| 九九在线观看视频 | 国产精品亚洲第一区柳州莫青 | 男女视频在线免费观看 | 国产视频a| 亚洲国产综合人成综合网站00 | 男女性高爱潮免费网站 | 一级毛片一级毛片一级毛片 | 色偷偷亚洲第一成人综合网址 | 欧美国产91| 国产成人亚洲综合一区 |