Re: [Pyparsing] Naming elements based on their predecessor
Brought to you by:
ptmcg
From: Joshua J. K. <jk...@sk...> - 2008-03-07 01:08:58
|
On Thu, 2008-03-06 at 18:23 -0600, Paul McGuire wrote: > You are the perfect straight-man! Uh, thanks? :) > What you describe is exactly what the Dict class is for. Dict is something > kind of unwieldy, so there is also a dictOf(key,value) helper method. Ah...spiffy. OK, so here's what I came up with: ext_prop = (p.Combine(p.Keyword('exec') + p.Keyword('sp_addextendedproperty'), joinString=" ", adjacent=False) + p.delimitedList(p.Dict(p.Group(p.Keyword('N').suppress() + p.QuotedString(quoteChar="'") + p.Literal(',').suppress() + p.Keyword('N').suppress() + p.QuotedString(quoteChar="'")))) ) And it seems to work just fine. Noticed something interesting: on a parsing object, an unknown attribute (such as 'asdfasdfsadf') will return '' (an empty string). Is this intended behavior? It makes testing for attributes via hasattr impossible. I can always test for an empty string, of course, but I'd rather use exceptions and catch an AttributeError than an if/then block to see if the string is non-emtpy. But that's just me. Anyway, thanks for the pointers. You've been a *huge* help. j -- Joshua Kugler VOC/SigNet Provider (aka Web App Programmer) S&K Aerospace Alaska |