擅长:python、mysql、java
<p>你误解了排他性的目的。它不是为了抑制输出中的那些字符,而是作为对初始字符串和正文字符串中给定字符的重写。所以这个</p>
<pre><code>Word(nums+'_', excludeChars='_')
</code></pre>
<p>就和</p>
^{pr2}$
<p>添加excludeChars是因为有很多次用户想要定义像:</p>
<ul>
<li>除“:”之外的所有可打印文件</li>
<li>除“,”或“.”之外的所有可打印文件</li>
<li>除。。。在</li>
</ul>
<p>在添加excludeChars之前,唯一的方法就是外观笨拙:</p>
^{3}$
<p>或者</p>
<pre><code>Word(printables.replace(',',''))
</code></pre>
<p>你现在可以写了</p>
<pre><code>Word(printables, excludeChars=',.')
</code></pre>
<p>在您的例子中,您希望解析数值,允许嵌入''u’s,但只返回数字。这是一个分析操作的好例子:</p>
<pre><code>integer = Word(nums+'_').setParseAction(lambda t: t[0].replace('_',''))
</code></pre>
<p>解析操作在解析时被调用来进行过滤和转换。甚至可以将转换包含在操作中:</p>
<pre><code>integer = Word(nums+'_').setParseAction(lambda t: int(t[0].replace('_','')))
integer.parseString('1_000') > [1000]
</code></pre>