擅长:python、mysql、java
<p>对于固定宽度格式,<a href="http://docs.python.org/2.7/tutorial/introduction.html#strings" rel="nofollow">string slicing</a>可能是解析的最佳方式:</p>
<pre><code>num = s[0:3]
score = s[4:9]
ping = s[10:14]
guid = s[15:47]
name = s[48:63]
...
</code></pre>
<p>一定要<a href="http://docs.python.org/2.7/library/stdtypes.html#str.strip" rel="nofollow"><em>strip</em></a>去掉多余的空白,必要时转换成<a href="http://docs.python.org/2.7/library/functions.html#int" rel="nofollow"><em>int</em></a>。你知道吗</p>
<p>通过将结果存储在<a href="http://docs.python.org/2.7/tutorial/introduction.html#lists" rel="nofollow">list</a>中,可以创建结果的“数组”:</p>
<pre><code>arr = [num, score, ping, guid, name, lastmsg, address, qport, rate]
</code></pre>