I’m using Python 2.7 to convert saved tuples to list/dictionaries.
Currently my code looks like this:
mystring = "\x80\x02]q\x01(J\x03\x00\x01\x00J\x15\xf93PK\x01K\x01G@\x834\x00\x00\x00\x00\x00K\x01K\x00e}q\x02(M\x03\xbb]q\x03(U\x0bmteststringq\x04Ml0U\x05_L-A_q\x05K\x00K\x02eJ\x06M\xd1\x1d]q\x06(U\x08otherstrq"
mystruct = str(len(mystring)) + 'B'
mydict = struct.unpack(mystruct, mystring)
In reality the string is longer, I shortened it.
This works for the integer values, but it contains also names like “mteststring” or “otherstr” – how do I get them out of the string along with their values?
As xiaomao commented, you’ll need to define the full structure in your mystruct string so something like:
gets you a little closer, in that it’s extracting the two strings. Of course if you’re writing both ends of this transaction, there are many other encoding methods that could be used, including some such as JSON or YAML which will make the data much more readable/portable.