python configparser
1、创建文件
import configparser cf = configparser.ConfigParser() cf.add_section('mysqld') cf.set('mysqld','port','3306') cf.set('mysqld','max_connection','1000') cf.add_section('client') cf.set('client','pid','/tmp/user.pid') cf.set('client','basedir','/var/usr/lib/mysql') with open('my.ini','w') as f: cf.write(f)
2、读取文件
cf = configparser.ConfigParser() cf.read('my.ini') print(cf['mysqld']['port'])