number of arguments a function takes

Corey Coughlin corey.coughlin at
Fri Jan 30 01:06:20 CET 2004

"Elaine Jackson" <elainejackson7355 at> wrote in message news:<YVbSb.319671$JQ1.192347 at pd7tw1no>...
> Exactly what I was looking for. Thank you very much.
> "Duncan Booth" <me at> wrote in message
> news:Xns947FAE6461014duncanrcpcouk at
> | "Elaine Jackson" <elainejackson7355 at> 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.
> |
> | >>>

So you're working on a truth table program?  I have a truth table
object I did for my own application, more focused on finding
input/output transitions in arbitrary truth tables, but if you're
interested, let me know.  Regardless, are you working on something
that will ultimately become public?  If so, be sure to announce it
when you're done, I'd love to have a look.  Especially if you're doing
anything with functional simplification, my object can return a simple
SOP function for a table (reducing out unused inputs is also an
option) but they can get kind of lengthy for complicated functions. 
And if you need any other help, be sure to let me know!

More information about the Python-list mailing list