import struct def getLen(_f): _data = _f.read(1) _a_l = _l = _data[0] while _l == 255: _data = _f.read(1) _l = _data[0] _a_l += _l return _a_l # with open('E:\\tmp\\ISLAND\\cst\\lin03_selA_ret.cstl', 'rb') as f: # data = f.read(8) # Header = struct.unpack_from('4sI', data) # print(Header) # al_len = getLen(f) # for i in range(al_len): # data = f.read(getLen(f)) # print(data) # al_len = getLen(f) * al_len * 2 # print('len', al_len) # while al_len > 0: # data = f.read(getLen(f)) # print(data.decode('utf-8')) # al_len -= 1 def getTxt(path): retn = [] with open(path, 'rb') as f: data = f.read(8) Header = struct.unpack_from('4sI', data) print(Header) al_len = getLen(f) for i in range(al_len): data = f.read(getLen(f)) print('语言', data) al_len = getLen(f) * al_len * 2 print('数量', al_len) while al_len > 0: data = f.read(getLen(f)) retn.append(data.decode('utf-8')) al_len -= 1 assert not f.read(1) return retn