On Sat, Apr 24, 2010 at 9:19 PM, Yingjie Lan <lany...@yahoo.com> wrote:
> 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?

A NameError Exception does not store the name of the
variable. it has two attributes: .args and .message
both of which contain (usually) a string such as:

"name 'x' is not defined"

cheers
James
-- 
http://mail.python.org/mailman/listinfo/python-list

Reply via email to