#-*- coding: GBK -*- #¶ÁÈ¡Óû§ÅäÖÃÎļþ #×÷Õߣºifo from Utils.DataFileReader import DataFileReader import logging import traceback class RobotsConfig( DataFileReader ): _SKIP_LINES = 2 _SKIP_COLUMNS = 0 def __init__(self,filename): DataFileReader.__init__( self ) self.configList = [] # Óû§ÅäÖÃÎļþµÄËùÔÚ·¾¶ try: if not self.Open(filename): # ´ò¿ªÎļþ logging.fatal( "Robot Config File[%s] no found" % filename ) return except Exception, e: print str(e) print traceback.print_exc() logging.error( str(e) ) logging.error( traceback.print_exc() ) logging.info( "Robot Config File[%s] open successfully" % filename ) def _ProcessData( self, datalist ): from ProjectBinding.ProjectRobotConfigParam import ProjectRobotConfigParams self.configList.append( ProjectRobotConfigParams(datalist) ) #·µ»ØÓÐЧÄÚÈÝÌõÊý def GetRecordCount(self): return len(self.configList) #ͨ¹ýË÷Òý·µ»ØÄÚÈÝ def GetRecordByIndex(self,index): return self.configList[index] def __str__(self): strRet = "" for param in self.configList: strRet += str(param) + "\n" return strRet __gRobotsConfig = None def ReadConfig( filename ): global __gRobotsConfig if not __gRobotsConfig: __gRobotsConfig = RobotsConfig( filename ) def GetConfig(): global __gRobotsConfig return __gRobotsConfig if __name__ == '__main__': ReadConfig("..\Configuration\User.txt") newConfig = GetConfig() print newConfig.GetRecordCount() print newConfig.GetRecordByIndex( 0 ) record = newConfig.GetRecordByIndex( 1 ) print record