Re: How to get the formal args of a function object?

2009-05-15 Thread kj
In Chris Rebert writes: >Take a look at inspect.getargspec(func): >http://docs.python.org/library/inspect.html#inspect.getargspec Thank you much, that did the trick. And inspect is a very handy module to know about. kynn -- NOTE: In my address everything before the first period is backwards

Re: How to get the formal args of a function object?

2009-05-14 Thread Scott David Daniels
norseman wrote: Scott David Daniels wrote: kj wrote: Suppose that f is an object whose type is 'function'. Is there a way to find out f's list of formal arguments?... I can write a wrapper now: def tracer(function): def internal(*args, **kwargs): print('calling %s(%s)'

Re: How to get the formal args of a function object?

2009-05-14 Thread norseman
Scott David Daniels wrote: kj wrote: Suppose that f is an object whose type is 'function'. Is there a way to find out f's list of formal arguments? The reason for this is that I'm trying to write a decorator and I'd like the wrapper to be able to check the number of arguments passedbut I'm

Re: How to get the formal args of a function object?

2009-05-14 Thread norseman
kj wrote: Suppose that f is an object whose type is 'function'. Is there a way to find out f's list of formal arguments? The reason for this is that I'm trying to write a decorator and I'd like the wrapper to be able to check the number of arguments passed. Specifically, I'd like the wrapper

Re: How to get the formal args of a function object?

2009-05-14 Thread Chris Rebert
On Thu, May 14, 2009 at 12:31 PM, kj wrote: > > > Suppose that f is an object whose type is 'function'. > > Is there a way to find out f's list of formal arguments? > > The reason for this is that I'm trying to write a decorator and > I'd like the wrapper to be able to check the number of argument

Re: How to get the formal args of a function object?

2009-05-14 Thread Scott David Daniels
kj wrote: Suppose that f is an object whose type is 'function'. Is there a way to find out f's list of formal arguments? The reason for this is that I'm trying to write a decorator and I'd like the wrapper to be able to check the number of arguments passedbut I'm missing something like the

Re: How to get the formal args of a function object?

2009-05-14 Thread Jeff McNeil
You can pull it out of f.func_code.co_varnames, but I don't believe that's a very good approach. I tend to veer away from code objects myself. If you know how many arguments are passed into the wrapped function when it's defined, you can write a function that returns your decorator. As an example.

How to get the formal args of a function object?

2009-05-14 Thread kj
Suppose that f is an object whose type is 'function'. Is there a way to find out f's list of formal arguments? The reason for this is that I'm trying to write a decorator and I'd like the wrapper to be able to check the number of arguments passed. Specifically, I'd like the wrapper to look as