Mark McEahern wrote:
Dan Eloff wrote:
How can you determine that func2 will only accept
bar and zoo, but not foo and call the function with
bar as an argument?
Let Python answer the question for you:
...
Please be aware the "normal" way to do this is go ahead and call
the function. Many "functio
Python 2.4 (#60, Nov 30 2004, 11:49:19) [MSC v.1310 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
Running startup script
Py> import inspect
Py> help(inspect.getargspec)
Help on function getargspec in module inspect:
getargspec(func)
Get the name
Awesome, wrapping that into a function:
def getargs(func):
numArgs = func.func_code.co_argcount
names = func.func_code.co_varnames
return names[:numArgs]
short, concise, and it works :)
variables declared inside the function body are also in co_varnames
but after the arguments only it s
Dan Eloff wrote:
How can you determine that func2 will only accept
bar and zoo, but not foo and call the function with
bar as an argument?
Let Python answer the question for you:
>>> def func2(bar='a', zoo='b'):
... pass
...
>>> for name in dir(func2):
... print '%s: %s' % (name, getattr(func2, na