![]() GvrTxt = struct.unpack("%ds" % length, textīut of course you could not use struct at all, if you are using just bytestrings: gvrTxt = text You can retrieve the size by slicing first the size of the first field, and passing it to unpack, and then, unpack the remaining of the struct: length = struct.unpack("B", text) ![]() ![]() You can't unpack this with the struct.unpack method without manually slicing it first, as you've noted, since UNPACK requires that the passed byte-string contained the packed values to be equal in size to the format passed. Txt = struct.pack('B' + str(len(gvrTxt)) + 's', len(gvrTxt), gvrTxt) Txt = struct.pack('B%ds' % len(gvrTxt), len(gvrTxt), gvrTxt) instead of Way to interpolate strings and numbers in Javascript, but in Python, you should use: If it is the case that you need space/performance, use an SQL engine - SQLITE will work fine.Īlso attempt for the fact the code above is hard to read Python - it may be the only Unless you are passing this as a data structure to a library that accepts the format you created above, you should not need to do that: store strings as text in text files - not as binary. I think the first question to answer is: Why are you packing strings like this in the first place? ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |