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
>> 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
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=
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
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