Getting the name which is not defined from NameError in python

后端 未结 3 1093
悲哀的现实
悲哀的现实 2021-01-17 22:51

As you know, if we simply do:

>>> a > 0
Traceback (most recent call last):
  File \"\", line 1, in 
    a > 0
N         


        
3条回答
  •  广开言路
    2021-01-17 23:27

    >>> import exceptions
    >>> try:
    ...     a > 0
    ... except exceptions.NameError, e:
    ...     print e
    ... 
    name 'a' is not defined
    >>> 
    

    You can parse exceptions string for '' to extract value.

提交回复
热议问题