配置文件 conf.ini
[connection]
# connection time out
connection_time_out = 60
# max connection
max_connection = 10
python 代码, main.py:
import configparser
file = 'conf.ini'
conf = configparser.ConfigParser()
conf.read(file, encoding='UTF-8')
connection = dict(conf.items('connection'))
print('connection_time_out: %s, max connection: %s'% (connection['connection_time_out'], connection['max_connection']))
在 shell 命令行执行 python main.py,得到如下输出:
connection_time_out: 60, max connection: 10