Getting the argument names passed to a function ?

Quinn Dunkan quinn at
Tue Apr 4 20:27:28 EDT 2000

On Tue, 04 Apr 2000 21:08:55 GMT, Fredrik Lundh <effbot at> wrote:
>Andreas Jung <ajung at> wrote:
>> def myfunc(arg1,arg2):
>> ...
>> a=1;b=2
>> myfunc(a,b)
>> Is it possible to get the name of variables that  were
>> used as arguments to call myfunc(). myfunc() should be
>> able to determine the names 'a' and 'b'. Don't ask
>> me why I need this - it's for a worse Python hack :-)
>short answer: no
>longer answer: maybe, using the incredibly clever and
>totally evil bytecodehacks stuff:

Hmm, could you say:

def arghack(arg):
    for k, v in globals().items():
        if arg is v:
            return k
        return None

Seems to work ok...

More information about the Python-list mailing list