infering the number of args a function takes at runtime

Lie Ryan lie.1296 at gmail.com
Mon Dec 8 07:16:24 EST 2008


On Mon, 08 Dec 2008 02:40:03 -0800, sniffer wrote:

> On Dec 8, 9:39 am, sniffer <a... at lspl.net> wrote:
>> hi all,
>> i am a python newbie, in a project currently doing i need to find out
>> the number of arguments that a function takes at runtime.? Is this
>> possible ,if so how do i do this,i ve looked through the python
>> documentation but couldnt find anything.any help will be great
>>
>> TIA
> 
> Thanks guys , i think this should work for me.btw as enquired i am
> working o a mvc thingie where in need to call functions in a
> controller,and pass the arguments as recieved from the end user so i
> need to make sure that the number of arguments passed from the front end
> are correct or not in the context of the function being called

In python, usually you'll just pass the them all and maybe catch errors.

def callback(*args, **kargs):
    try:
        return func(*args, **kargs)
    except TypeError:
        print('An error happened')




More information about the Python-list mailing list