日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程语言 > python >内容正文

python

python 之configparser模块

發布時間:2023/12/13 python 27 豆豆
生活随笔 收集整理的這篇文章主要介紹了 python 之configparser模块 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

該模塊的作用?就是使用模塊中的RawConfigParser()、ConfigParser()、?SafeConfigParser()這三個方法(三者擇其一),創建一個對象使用對象的方法對指定的配置文件做增刪改查?操作。

1.【創建一個配置文件的方法步驟】

import configparserconfig=configparser.ConfigParser() #按字典的方式添加 config["DEFAULT"]={'ServerAliceIntervale':'45','Compression':'Yes','ComperssionLevel':'9'} config['bitbucket.org']={'User':'kebi'} config['topsecret.server.com']={'Host Port':'50022','ForwardXll':'no'} # topsecret=config['topsecret.server.com'] # topsecret['Host Port']='50022' # topsecret['ForwardXll']='no' config['DEFAULT']['ForwardXll']='yes'#寫入文件 with open(r'example.ini','w') as configfile:config.write(configfile)

【3】讀取文件

# 讀取文件 config.read('example.ini') print(config.sections()) #返回可用的section的列表;默認section不包括在列表中 print(config.defaults())# 返回包含實例范圍默認值的字典。print('ddddd',config.options('bitbucket.org'))#獲取所有的配置表名字key for key in config['bitbucket.org']:#返回所有的可以,不僅僅是這個建值對下的keyprint(key)

【4】刪除,修改

#刪除 #config.remove_section('topsecret.server.com')#config.set('bitbucket.org','age','22')#要賦值的話,賦值完要重新寫入,不然不成功 #修改 #config.set('bitbucket.org','user','zhanmus') config.remove_option('bitbucket.org','user')#通過鍵值對刪除 #重新寫入 config.write(open('example.ini','w'))#修改刪除都要重新寫入,不然不成功

轉載于:https://www.cnblogs.com/lanyinhao/p/9158781.html

總結

以上是生活随笔為你收集整理的python 之configparser模块的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。