试试看:
如果分区已经存在,则必须读取该分区的所有键和值
然后写下整个剖面数据# -*- coding: cp950 -*-
import configobj
import os
# -
# _readINI(ini_file, szSection, szKey)
# read KeyValue from a ini file
# return True/False, KeyValue
# -
def _readINI(ini_file, szSection, szKey=None):
ret = None
keyvalue = None
if os.path.exists(ini_file) :
try:
config = configobj.ConfigObj(ini_file, encoding='UTF8')
if not szKey==None :
keyvalue = config[szSection][szKey]
else:
keyvalue = config[szSection]
ret = True
print keyvalue
except Exception, e :
ret = False
return ret, keyvalue
# -
# _writeINI(ini_file, szSection, szKey, szKeyValue):
# write key value into a ini file
# return True/False