擅长:python、mysql、java
<p>这可以用二进制字符串来解决:</p>
<pre><code>import struct
header = line[:2]
if header!=b'$$':
raise RuntimeError('Wrong header')
# Assumes you want two have 2 bytes, not one word
L = struct.unpack('BB',line[2:4])
ID = struct.unpack('7B', line[4:11])
location = line[11:]
print 'L={},{}, ID={}, location={}'.format(L[1],L[2], ''.join(str(b) for b in ID, location)
</code></pre>
<p>另一个答案是指向struct的链接</p>