1, copy 2.7 version of the configparser.py module supports the value-free parsing
cp/usr/local/src/python-2.7.5/lib/configparser.py/usr/lib/python2.6/
2. Import and use
Import Configparser
c = Configparser.configparser ()
C.read ('/etc/my.cnf ')
c.sections () out[8]: ['Client','mysqld','mysqldump','MySQL','Myisamchk','mysqlhotcopy']
C.options ('mysqld') out[9]: ['Port','Socket','skip-locking','key_buffer_size','Max_allowed_packet','Table_open_cache','sort_buffer_size','read_buffer_size','read_rnd_buffer_size','myisam_sort_buffer_size','thread_cache_size','query_cache_size','thread_concurrency','Log-bin','Binlog_format','Server-id']
C.get (' mysqld ', ' Port ')
OUT[10]: ' 3306 '
Can be modified or added: Set (Self, section, option, Value=none)
Save content: C.write ()
With open ('/tmp/mysql.cnf ', ' W ') as FD:
C.wirte (FD)
python-managing MySQL's Configparser module