python 配置文件操作

引入庫

import configparser

配置文件讀取

樣例配置文件

[DEFAULT]
ServerAliveInterval = 45
Compression = yes
CompressionLevel = 9
ForwardX11 = yes
  
[bitbucket.org]
User = Atlan
  
[topsecret.server.com]
Port = 50022
ForwardX11 = no
config = configparser.ConfigParser()
config.read('example.ini')
print(config['bitbucket.org']['user'])

config相當於是一個字典,讀出的所有值均爲字符串,如果有需要,手動轉換即可

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章