Re: [Pyparsing] Naming elements based on their predecessor
Brought to you by:
ptmcg
From: Paul M. <pa...@al...> - 2008-03-07 01:19:37
|
>>>> 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 -- Paul |