Breaking up Strings correctly:

Gabriel Genellina gagsl-py2 at yahoo.com.ar
Mon Apr 9 15:18:46 EDT 2007


En Mon, 09 Apr 2007 12:39:44 -0300, Paul McGuire <ptmcg at austin.rr.com>  
escribió:

> On Apr 9, 7:19 am, "Michael Yanowitz" <m.yanow... at kearfott.com> wrote:
>>
>>    Suppose I have a string of expressions such as:
>> "((($IP = "127.1.2.3") AND ($AX < 15)) OR (($IP = "127.1.2.4") AND ($AY  
>> !=
>> 0)))
>>   I would like to split up into something like:
>>
>> [ "OR",
>>   ["AND", "($IP = "127.1.2.3")", "($AX < 15)"],
>>   ["AND", "(($IP = "127.1.2.4")", ($AY != 0))"] ]
>>
>
> This problem is right down the pyparsing fairway!  Pyparsing is a
> module for defining recursive-descent parsers, and it has some built-
> in help just for applications such as this.

Sometimes I've seen you proposing the usage of PyParsing on problems that,  
in my opinion, were better solved using some other standard tools, but  
this time you're absolutely right: this is perfectly suited for PyParsing!  
:)

-- 
Gabriel Genellina




More information about the Python-list mailing list