国产片侵犯亲女视频播放_亚洲精品二区_在线免费国产视频_欧美精品一区二区三区在线_少妇久久久_在线观看av不卡

腳本之家,腳本語言編程技術及教程分享平臺!
分類導航

Python|VBS|Ruby|Lua|perl|VBA|Golang|PowerShell|Erlang|autoit|Dos|bat|

服務器之家 - 腳本之家 - Python - Python configparser模塊操作代碼實例

Python configparser模塊操作代碼實例

2020-06-09 10:09wenbin_ouyang Python

這篇文章主要介紹了Python configparser模塊操作代碼實例,文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友可以參考下

1、生成配置文件

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
'''
  生成配置文件
'''
import configparser
 
config = 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 parser
topsecret['ForwardX11'] = 'no' # same here
 
with open('example.ini', 'w') as configfile:
  config.write(configfile)

2、讀取配置文件

?
1
2
3
4
5
6
7
8
9
10
11
12
13
# 讀
import configparser
config = configparser.ConfigParser()
config.sections()
config.read('example.ini')
# {'serveraliveinterval': '45', 'compression': 'yes', 'compressionlevel': '9', 'forwardx11': 'yes'}
print(config.defaults())
 
# hg
print(config['bitbucket.org']["User"])
 
# 50022
print(config["topsecret.server.com"]["host port"])

3、刪除

?
1
2
3
4
5
6
7
8
# 刪除(創建一個新文件,并刪除 bitbucket.org)
import configparser
config = configparser.ConfigParser()
config.sections()
 
config.read('example.ini')
rec = config.remove_section("bitbucket.org") # 刪除該項
config.write(open("example.cfg","w"))

生成新文件 example.cfg

?
1
2
3
4
5
6
7
8
9
DEFAULT]
serveraliveinterval = 45
compression = yes
compressionlevel = 9
forwardx11 = yes
 
topsecret.server.com]
host port = 50022
forwardx11 = no

刪除,并覆蓋原文件

?
1
2
3
4
5
6
7
8
# 刪除(刪除 bitbucket.org)
import configparser
config = configparser.ConfigParser()
config.sections()
 
config.read('example.ini')
rec = config.remove_section("bitbucket.org") # 刪除該項
config.write(open("example.ini","w"))

4、修改

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
import configparser
 
config = configparser.ConfigParser()
 
config.read('example.ini') #讀文件
 
config.add_section('yuan') #添加section
 
config.remove_section('bitbucket.org') #刪除section
config.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

?
1
2
3
4
5
6
7
8
9
10
11
12
[DEFAULT]
serveraliveinterval = 45
compression = yes
compressionlevel = 9
forwardx11 = yes
 
[topsecret.server.com]
host port = 50022
k1 = 11111
 
[yuan]
k2 = 22222

以上就是本文的全部內容,希望對大家的學習有所幫助,也希望大家多多支持服務器之家。

原文鏈接:https://www.cnblogs.com/xy-ouyang/p/12986386.html

延伸 · 閱讀

精彩推薦
Weibo Article 1 Weibo Article 2 Weibo Article 3 Weibo Article 4 Weibo Article 5 Weibo Article 6 Weibo Article 7 Weibo Article 8 Weibo Article 9 Weibo Article 10 Weibo Article 11 Weibo Article 12 Weibo Article 13 Weibo Article 14 Weibo Article 15 Weibo Article 16 Weibo Article 17 Weibo Article 18 Weibo Article 19 Weibo Article 20 Weibo Article 21 Weibo Article 22 Weibo Article 23 Weibo Article 24 Weibo Article 25 Weibo Article 26 Weibo Article 27 Weibo Article 28 Weibo Article 29 Weibo Article 30 Weibo Article 31 Weibo Article 32 Weibo Article 33 Weibo Article 34 Weibo Article 35 Weibo Article 36 Weibo Article 37 Weibo Article 38 Weibo Article 39 Weibo Article 40
主站蜘蛛池模板: 精品视频久久 | 日本午夜在线 | 成人日韩 | 中文字幕在线视频观看 | 中文字幕在线观看一区 | 久久综合区 | 不卡二区| sis001亚洲原创区 | 欧洲精品码一区二区三区免费看 | 韩国精品一区 | 亚洲视频在线观看 | 国产精品久久久精品 | 国产资源在线看 | 国产福利视频在线观看 | 国产成人久久精品一区二区三区 | 中文字幕在线播放一区 | 日韩在线精品视频 | 久久久久久91香蕉国产 | 淫片一级国产 | 日韩色综合 | 国产精品无码久久久久 | 国产精品视频免费观看 | 欧美日韩一区二区三区不卡视频 | 99看片| 在线视频 亚洲 | 午夜影视免费观看 | 欧美一级二级视频 | 日韩在线播放一区二区 | 久久久精| 国产aaaaav久久久一区二区 | 精品成人一区二区 | 中文字幕日韩av | 天堂中文网| 毛片一卡 | 色在线看 | 一区二区三区影视 | 亚洲精品一区二区三区 | 国产老头老太作爱视频 | 亚洲在线观看一区二区 | 麻豆av电影在线观看 | 日韩午夜一级片 |