NameError: how to get the name?

Yingjie Lan lanyjie at
Sat Apr 24 07:19:43 EDT 2010

I wanted to do something like this:

while True:
    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,



More information about the Python-list mailing list