Getting the argument names passed to a function ?

Andreas Jung ajung at sz-sb.de
Wed Apr 5 08:00:43 CEST 2000


> import sys
> def arghack(arg):
>     try:
>         1/0
>     except:
>         frame = sys.exc_info()[2].tb_frame.f_back
>     while frame:
>         for k, v in frame.f_locals.items():
>             if arg is v:
>                 return k
>         frame = frame.f_back
>     else:
>         return None

That's the perfect solution I was looking for :-) Thanks !

Cheers,
Andreas




More information about the Python-list mailing list