python pack以字符串格式输出

2 python struct pack

我做了以下事情.

from struct import pack, unpack
t = 1234
tt = str(pack("<I", t))
Run Code Online (Sandbox Code Playgroud)

打印tt给出\xf3\xe0\x01\x00.如何t从tt 获取原始值?

我尝试使用解压缩,repr(tt)但这没有用.我该怎么做呢?

N 1*_*1.1 7

>>> t=1234
>>> tt=pack('<I', t)
>>> tt
'\xd2\x04\x00\x00'
>>> unpack('<I', tt)
(1234,)

>>> ttt, = unpack('<I', tt) 
>>> ttt
1234
Run Code Online (Sandbox Code Playgroud)