Import ConfigParser Import OS Class ReadWriteConfFile: CurrentDir = OS. path. dirname (_ file __) Filepath = currentDir + OS. path. sep + "inetMsgConfigure. ini" @ Staticmethod Def getConfigParser (): Cf = ConfigParser. ConfigParser () Cf. read (ReadWriteConfFile. filepath) Return cf @ Staticmethod Def writeConfigParser (cf ): F = open (ReadWriteConfFile. filepath, "w "); Cf. write (f) F. close (); @ Staticmethod Def getSectionValue (section, key ): Cf = ReadWriteConfFile. getConfigParser () Return cf. get (section, key) @ Staticmethod Def addSection (section ): Cf = ReadWriteConfFile. getConfigParser () AllSections = cf. sections () If section in allSections: Return Else: Cf. add_section (section) ReadWriteConfFile. writeConfigParser (cf) @ Staticmethod Def setSectionValue (section, key, value ): Cf = ReadWriteConfFile. getConfigParser () Cf. set (section, key, value) ReadWriteConfFile. writeConfigParser (cf) If _ name _ = '_ main __': ReadWriteConfFile. addSection ('messages ') ReadWriteConfFile. setSectionValue ('messages ', 'name', 'sophia ') X = ReadWriteConfFile. getSectionValue ('messages ', '123 ') Print x |