RE: parsing function parameters

2011-08-03 Thread Lee Harr
Needed to make one change... for functions with no default args: def pdict(f):     parameter_defaults = {}     defaults = f.func_defaults     if defaults is not None:     defaultcount = len(defaults)     else:     defaultcount = 0     argcount = f.func_code.co_argcount     for i in xrang

RE: parsing function parameters

2011-08-03 Thread Lee Harr
>> I am trying to get some information about a function >> before (and without) calling it. > how about def pdict(f):     parameter_defaults = {}     defaults = f.func_defaults     defaultcount = len(defaults)     argcount = f.func_code.co_argcount     for i in xrange(f.func_code.co_argco

Re: parsing function parameters

2011-08-03 Thread Peter Otten
Lee Harr wrote: > I am trying to get some information about a function > before (and without) calling it. If you allow for the function arguments to be evaluated it's easy (requires Python 2.7): >>> import inspect >>> def get_args(*args, **kw): ... return args, kw ... >>> argstr = "1, 2, z=

Re: parsing function parameters

2011-08-03 Thread Stefan Behnel
Lee Harr, 03.08.2011 18:02: I am trying to get some information about a function before (and without) calling it. Here is what I have so far. I chose to go with a regular expression, so now I have 2 problems :o) Can't you just use runtime introspection? Take a look at the inspect module. Stef

parsing function parameters

2011-08-03 Thread Lee Harr
I am trying to get some information about a function before (and without) calling it. Here is what I have so far. I chose to go with a regular expression, so now I have 2 problems :o) def pdict(f, pstr):     '''given a function object and a string with the function parameters,     return a dic