#-*- coding: GBK -*- #¶ÁÈ¡Óû§ÅäÖÃÎļþ #×÷Õߣºifo import DataFileReader import logging import traceback class tagRoleItem( DataFileReader.DataFileReader ): _SKIP_LINES = 1 _SKIP_COLUMNS = 0 def __init__(self,filename): DataFileReader.DataFileReader.__init__( self ) self.configList = [] # Óû§ÅäÖÃÎļþµÄËùÔÚ·¾¶ try: if not self.Open(filename): # ´ò¿ªÎļþ logging.fatal( "tagRoleItem 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( "tagRoleItem File[%s] open successfully" % filename ) def _ProcessData( self, datalist): import tagRoleItemParam self.configList.append( tagRoleItemParam.tagRoleItemParam(datalist,self.commentline) ) #·µ»ØÓÐЧÄÚÈÝÌõÊý def GetRecordCount(self): return len(self.configList) #ͨ¹ýË÷Òý·µ»ØÄÚÈÝ def GetRecordByIndex(self,index): return self.configList[index] def GetCommentLine(self): commentlinelist = self.commentline.replace( "\n", "\t" ).split( "\t" ) commentlinelist.pop() return commentlinelist def __str__(self): strRet = "" for param in self.configList: strRet += str(param) + "\n" return strRet __gtagRoleItem = None def ReadConfig( filename ): global __gtagRoleItem if not __gtagRoleItem: __gtagRoleItem = tagRoleItem( filename ) def GetConfig(): global __gtagRoleItem return __gtagRoleItem if __name__ == '__main__': ReadConfig("tagRoleItem.txt") newConfig = GetConfig() print newConfig.GetRecordCount() record1 = newConfig.GetRecordByIndex( 2 ) # record2 = newConfig.GetRecordByIndex( 100 ) # print record2.GetAccID() # print record2.Adult print record1.Sex,record1.Job print newConfig.GetCommentLine() print newConfig.__str__()