Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > infering the number of args a function takes at runtime

Reply
Thread Tools

infering the number of args a function takes at runtime

 
 
sniffer
Guest
Posts: n/a
 
      12-08-2008
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
 
Reply With Quote
 
 
 
 
Chris Rebert
Guest
Posts: n/a
 
      12-08-2008
On Sun, Dec 7, 2008 at 8:39 PM, sniffer <(E-Mail Removed)> 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


You want inspect.getargspec() or one of its friends in the `inspect`
module. See http://docs.python.org/library/inspe...ect.getargspec

Cheers,
Chris

--
Follow the path of the Iguana...
http://rebertia.com
I really should get back to studying now

>
>
> TIA
> --
> http://mail.python.org/mailman/listinfo/python-list
>

 
Reply With Quote
 
 
 
 
James Mills
Guest
Posts: n/a
 
      12-08-2008
On Mon, Dec 8, 2008 at 2:45 PM, Chris Rebert <(E-Mail Removed)> wrote:
> On Sun, Dec 7, 2008 at 8:39 PM, sniffer <(E-Mail Removed)> 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

>
> You want inspect.getargspec() or one of its friends in the `inspect`
> module. See http://docs.python.org/library/inspe...ect.getargspec


Also, I have to ask: Why do you need to do this ?
Please show some code samples of what you're trying to achieve
and what the problem is ?

cheers
James

--
--
-- "Problems are solved by method"
 
Reply With Quote
 
sniffer
Guest
Posts: n/a
 
      12-08-2008
On Dec 8, 9:39*am, sniffer <(E-Mail Removed)> 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
 
Reply With Quote
 
Lie Ryan
Guest
Posts: n/a
 
      12-08-2008
On Mon, 08 Dec 2008 02:40:03 -0800, sniffer wrote:

> On Dec 8, 9:39*am, sniffer <(E-Mail Removed)> 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')

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
state machine and register infering Olaf VHDL 6 05-29-2007 09:27 PM
ram not infering as block ram ashu VHDL 1 11-06-2006 01:51 PM
ram not infering as block ram ashu VHDL 2 11-06-2006 05:01 AM
Infering a sequential in RTL rohit.nadig@gmail.com VHDL 4 10-16-2006 03:58 PM
When passing functions as args,how to pass extra args for passed function? python@sarcastic-horse.com Python 3 09-17-2003 12:25 AM



Advertisments