首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > perl python >

python模拟windows获取设立ini

2012-11-06 
python模拟windows获取设置ini#!/usr/bin/env pythonfrom ConfigParser import ConfigParserdef GetIniSt

python模拟windows获取设置ini

#!/usr/bin/env pythonfrom ConfigParser import ConfigParser;def GetIniString(strFile, strSection, strKey):    strNullRet = ""    if (not os.path.exists(strFile)) or (not strSection) or (not strKey):        return strNullRet    cfg = ConfigParser()    try:        cfg.read(strFile)        if not cfg.has_section(strSection):            return strNullRet        strVal = cfg.get(strSection, strKey)    except:        return strNullRet    return strValdef SetIniString(strFile, strSection, strKey, strVal):    bRet = False;        if (not strFile) or (not strSection) or (not strKey) or (not strVal):        return False;    cfg = ConfigParser();    try:        cfg.read(strFile);        if not cfg.has_section(strSection):            cfg.add_section(strSection);        cfg.set(strSection, strKey, strVal);        cfg.write(open(strFile, 'w'));        bRet = True;    except:        return False;    return bRetSetIniString("./a.txt", "a", "b", "c");
?

热点排行