get the list of expected arguments?
Michal Wallace (sabren)
sabren at manifestation.com
Mon May 8 17:38:35 EDT 2000
Hey all,
Given a function (or method), is it possible to know the names of the
expected parameters? I'd like to be able to extract this information
and generate a form for calling the function.
For example, say you have a function that draws a line:
def line(m,b, x1=0, x2=10):
for x in range(x1, x2):
y = m * x + b
plot(x,y)
... It might be in a module with a bunch of other geometry functions.
I'd like to do something like "showForm(line)" and get:
ENTER PARAMETERS FOR LINE:
m: _____
b: _____
x1: ___0
x2: __10
Is that possible? I tried dir(line), and got:
['__doc__', '__name__', 'func_code', 'func_defaults', 'func_doc',
'func_globals', and 'func_name']
Func_defaults gives me the 0 and 10, but none of these seem to help
with giving the names. Could it possibly be done with a bytecode
hack on func_code? Or am I missing something totally obvious?
I'm going to keep digging, but I thought I'd ask in case anyone's done
this before..
Cheers,
- Michal
-------------------------------------------------------------------------
http://www.manifestation.com/ http://www.linkwatcher.com/metalog/
-------------------------------------------------------------------------
More information about the Python-list
mailing list