[Pyparsing] tokens.has_key('abc') throws exception
Brought to you by:
ptmcg
From: cathal c. <cof...@gm...> - 2011-07-02 22:19:27
|
Hey Guys, I am using setResultsName like this setResultsName('new_field_name') then inside my parse action I want to do something like the below. if tokens.has_key('new_field_name'): #Do something else: #Do something else However this causes an exception to be thrown. I guess tokens is not a dict even tho it appears to function like one. My not so elegant solution to avoid this problem is the below. try: new_field_name = tokens['new_field_name'] #Do something except: #Do something else I don't like this try -> except approach, does anyone have a more elegant solution? Kind regards, Cathal |