number of arguments a function takes
Elaine Jackson
elainejackson7355 at home.com
Thu Jan 29 13:03:36 EST 2004
Exactly what I was looking for. Thank you very much.
"Duncan Booth" <me at privacy.net> wrote in message
news:Xns947FAE6461014duncanrcpcouk at 127.0.0.1...
| "Elaine Jackson" <elainejackson7355 at home.com> wrote in
| news:CSaSb.329909$ts4.189798 at pd7tw3no:
|
| > Suppose one of the arguments of a function f_1 is another function
| > f_2. Can f_1 access the number of arguments taken by f_2? (I'm
| > writing a little script to automate the construction of logical
| > truth-tables.) Thanks.
|
| Look at the inspect module, in particular you probably want
| inspect.getargspec:
|
| >>> import inspect
| >>> def f(a,b): pass
|
| >>> inspect.getargspec(f)
| (['a', 'b'], None, None, None)
| >>> help(inspect.getargspec)
| Help on function getargspec in module inspect:
|
| getargspec(func)
| Get the names and default values of a function's arguments.
|
| A tuple of four things is returned: (args, varargs, varkw, defaults).
| 'args' is a list of the argument names (it may contain nested lists).
| 'varargs' and 'varkw' are the names of the * and ** arguments or None.
| 'defaults' is an n-tuple of the default values of the last n arguments.
|
| >>>
More information about the Python-list
mailing list