擅长:python、mysql、java
<p><a href="https://docs.python.org/release/1.5.2p2/" rel="nofollow">Python 1.5.2p2 documentation</a>在线提供。实际上,在<code>str</code>或模块<a href="https://docs.python.org/release/1.5.2p2/lib/module-string.html" rel="nofollow">^{<cd3>}</a>中都没有<code>isdigit</code>。你知道吗</p>
<hr/>
<p>即使在Python 1.5中,<code>str</code>也是一个支持<code>in</code>操作的序列,因此您可以执行以下操作:</p>
<pre><code>def isdigit(c):
return c in '0123456789'
pumpb = int(filter(isdigit, pump))
</code></pre>
<hr/>
<p>为了更彻底的解析,我将使用正则表达式,而使用模块<a href="https://docs.python.org/release/1.5.2p2/lib/module-re.html" rel="nofollow">^{<cd6>}</a>;代码</p>
<pre><code>import re
match = re.search('#ADC:\s*(\d+)', pump)
if match:
number = match.group(1)
</code></pre>
<p>这将匹配<code>#ADC:</code>,后跟任意数量的空格,后跟一个或多个数字<code>[0-9]</code>;这些数字被捕获在组<code>1</code>中,如果找到匹配,则该组的值将存储到<code>number</code>。你知道吗</p>