【Python】读取INI文件作为配置文件并定义编码

遇到问题,解决问题,记录解决方案,一气呵成


from configparser import ConfigParser


'''
;config.ini
[DEFAULT]
ServerAliveInterval = 45
Compression = yes
CompressionLevel = 9
ForwardX11 = yes
'''
cfg = ConfigParser()
# 用utf-8编码打开config.ini文件
cfg.read('config.ini', encoding="utf-8")
cfg.sections()


cfg.get('DEFAULT', 'ServerAliveInterval')
cfg.get('DEFAULT', 'Compression')
cfg.get('DEFAULT', 'CompressionLevel')
cfg.get('DEFAULT', 'ForwardX11')
点赞
  1. sex说道:
    Google Chrome Windows 10
    This piece oof writing gives clear iddea in favor of the new viewers of blogging, that really how to do blogging. Walter Hai
  2. gimmerm说道:
    Google Chrome Windows 8.1
    lasix tablet Does Vagifem Tablet Interact with other Medications

发表回复

电子邮件地址不会被公开。必填项已用 * 标注