Re: [Pyparsing] setDefaultWhitespaceChars
Brought to you by:
ptmcg
From: Paul M. <pt...@au...> - 2009-07-15 04:20:08
|
> I am trying to make "\t" significant by passing a string that doesn't > include "\t" to setDefaultWhitespaceChars. > However, it still seems to recognize '\t' as a white space. > > >>> ParserElement.setDefaultWhitespaceChars("\n\r ") > >>> words = Word(alphas) > >>> sentence = OneOrMore(words) + '.' > >>> print sentence.parseString("\tHello World.") > ['Hello', 'World', '.'] > This requirement doesn't come up too often, so it takes people by surprise. In order to keep columns straight, parseString calls expandtabs on the provided string before it begins parsing. You can suppress this by calling the parseWithTabs method on your top-level expression: >>> sentence.parseWithTabs() {{W:(abcd...)}... "."} >>> print sentence.parseString("\tHello World.") Traceback (most recent call last): File "<stdin>", line 1, in <module> File "C:\Python25\lib\site-packages\pyparsing.py", line 1076, in parseString raise exc pyparsing.ParseException: Expected W:(abcd...) (at char 0), (line:1, col:1) -- Paul |