def readOne(self): try: data = self.fp.read(RECORD_STRUCT.size) record = RECORD_STRUCT.unpack(data) except Exception, e: if self.fp.tell() >= self._record2pos(self.length): raise ScidException('End of file reached') else: raise e
def readOne(self): try: data = self.fp.read(RECORD_STRUCT.size) record = RECORD_STRUCT.unpack(data) except Exception, e: if self.fp.tell() >= self._record2pos(self.length): raise ScidException("End of file reached") else: raise e
def readIter(self, limit=None): batch = 1000 remain = self.length - self.tell() record_struct_size = RECORD_STRUCT.size i = 0 while True: if batch > remain: batch = remain if limit and limit <= i or batch == 0: return remain -= batch i += batch data = self.fp.read(record_struct_size * batch) for x in range(batch): #yield ScidRecord.from_struct() yield RECORD_STRUCT.unpack_from(data, x * record_struct_size)
def readIter(self, limit=None): batch = 1000 remain = self.length - self.tell() record_struct_size = RECORD_STRUCT.size i = 0 while True: if batch > remain: batch = remain if limit and limit <= i or batch == 0: return remain -= batch i += batch data = self.fp.read(record_struct_size * batch) for x in range(batch): # yield ScidRecord.from_struct() yield RECORD_STRUCT.unpack_from(data, x * record_struct_size)
def write(self, record): self.fp.write(RECORD_STRUCT.pack(*record))