示例#1
0
 def __init__(self, filename):
     self.__file = BinaryRecordFile.BinaryRecordFile(
         filename, _BIKE_STRUCT.size)
     self.__index_from_identity = {}
     for index in range(len(self.__file)):
         record = self.__file[index]
         bike = _bike_from_record(record)
         self.__index_from_identity[bike.identity] = index
示例#2
0
import struct
import BinaryRecordFile

filename = 'test.bin'

Contact = struct.Struct("<15si")
contacts = BinaryRecordFile.BinaryRecordFile(filename, Contact.size)
contacts[4] = Contact.pack("Abe Baker".encode("utf8"), 762)
contacts[5] = Contact.pack("Cindy Dove".encode("utf8"), 987)

contact_data = Contact.unpack(contacts[5])
contact_data[0].decode("utf8").rstrip(chr(0))  # вернет: 'Cindy Dove'