Re: [Pyparsing] Naming elements based on their predecessor
Brought to you by:
ptmcg
From: Joshua J. K. <jk...@sk...> - 2008-03-07 01:29:37
|
On Thu, 2008-03-06 at 19:19 -0600, Paul McGuire wrote: > >>>> > 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. > >>>> > > To test for the existence of an attribute: > - if 'alsfjlsjafs' in results: > - if results.alkjasdlfjslf == '': > or if results.laksjdfljsd: # evaluating to '' is a boolean false value > - results["sldflsjf"] will raise an exception if no such attribute Right, I figured that out (testing on the empty value anyway), but it surprised me that an invalid attribute didn't raise an exception. Thanks again for all your help. j -- Joshua Kugler VOC/SigNet Provider (aka Web App Programmer) S&K Aerospace Alaska |