NameError: how to get the name?

Yingjie Lan lanyjie at yahoo.com
Sat Apr 24 13:19:43 CEST 2010


I wanted to do something like this:

while True:
  try:
    def fun(a, b=b, c=c): pass
  except NameError as ne:
    name = get_the_var_name(ne)
    locals()[name] = ''
  else: break

What's be best way to implement the function 
get_the_var_name(ne) that returns the name
of the variable that could not be found?

Thanks in advance,

Yingjie


      



More information about the Python-list mailing list