473,322 Members | 1,188 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,322 software developers and data experts.

How to query a function and get a list of expected parameters?

I'm writing a function that accepts a function as an argument, and I
want to know to all the parameters that this function expects. How can
I find this out in my program, not by reading the source?

For example, I would want to know for the function below that I have to
pass in two things:

def f(x1, x2): return x1 * x2

It would be nice to get the names also.

All help is welcome.

TIA

Matt

--
A better way of running series of SAS programs:
http://overlook.homelinux.net/wilson...asAndMakefiles
Sep 29 '06 #1
2 1233
Matt,

In [26]: inspect.getargspec(f)
Out[26]: (['x1', 'x2'], None, None, None)

For more see the inspect module.

-Nick Vatamaniuc

Matthew Wilson wrote:
I'm writing a function that accepts a function as an argument, and I
want to know to all the parameters that this function expects. How can
I find this out in my program, not by reading the source?

For example, I would want to know for the function below that I have to
pass in two things:

def f(x1, x2): return x1 * x2

It would be nice to get the names also.

All help is welcome.

TIA

Matt

--
A better way of running series of SAS programs:
http://overlook.homelinux.net/wilson...asAndMakefiles
Sep 29 '06 #2
Matthew Wilson wrote:
I'm writing a function that accepts a function as an argument, and I
want to know to all the parameters that this function expects. How can
I find this out in my program, not by reading the source?

For example, I would want to know for the function below that I have to
pass in two things:

def f(x1, x2): return x1 * x2

It would be nice to get the names also.

All help is welcome.

TIA

Matt
Check out the inspect module
(http://www.python.org/doc/current/li...nctions.html):
>>from inspect import getargspec
getargspec(f)
(['x1', 'x2'], None, None, None)

George

Sep 29 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
by: Yisroel Markov | last post by:
I have the following in my code: strSQL = "SELECT tblTransactions.PshpID, tblTransactions.TransDate, " _ & " Sum(tblTransactions.DDAmount) AS SumDDAmount FROM tblTransactions " _ & "INNER JOIN...
4
by: paii, Ron | last post by:
I am trying to use the following "Elookup" function on a query that gets 2 parameters from an open form. ?eLookup("", "qryWOLPCMatEst") Returns the following error. Too few parameters....
7
by: Mark | last post by:
Hello. I am developing an Access 2000 form, and I want to populate a databound list box using a saved query that requires parameters. Is there any way to do this? I tried creating a DAO querydef...
10
by: Fredrik Tolf | last post by:
If I have a variable which points to a function, can I check if certain argument list matches what the function wants before or when calling it? Currently, I'm trying to catch a TypeError when...
36
by: Liam.M | last post by:
hey guys, I have one last problem to fix, and then my database is essentially done...I would therefore very much appreciate any assistance anyone would be able to provide me with. Currently I...
4
by: Tony Lownds | last post by:
(Note: PEPs in the 3xxx number range are intended for Python 3000) PEP: 3107 Title: Function Annotations Version: $Revision: 53169 $ Last-Modified: $Date: 2006-12-27 20:59:16 -0800 (Wed, 27 Dec...
9
by: Kelii | last post by:
I've been trying to get this piece to work for a few hours, but have given up. I hope someone out there can help, I think the issue is relatively straightforward, but being a novice, I'm stumped....
0
by: CJM | last post by:
I have a fairly simple ASP application talking to an Oracle 10g DB using a mixture of ADO (OraOLEDB) and OO4O - the query here concerns some ADO code. One part of the application records...
12
by: Yash | last post by:
My SQL query is like: SELECT ..... FROM tblCLAIM C INNER join tblXXX .... INNER join tblYYY ....(5 more joins) WHERE C.created_date between @start_date and @end_date AND...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.