As you know, if we simply do:
>>> a > 0 Traceback (most recent call last): File \"\", line 1, in a > 0 N
>>> import re >>> try: ... a>0 ... except (NameError,),e: ... print re.findall("name '(\w+)' is not defined",str(e))[0] a
If you don't want to use regex, you could do something like this instead
>>> str(e).split("'")[1] 'a'