Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #10819
| From | Lee Harr <missive@hotmail.com> |
|---|---|
| Subject | RE: parsing function parameters |
| Date | 2011-08-03 22:30 +0430 |
| References | <1312388985.25995.11.camel@tim-laptop> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.1857.1312394477.1164.python-list@python.org> (permalink) |
>> 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_argcount):
name = f.func_code.co_varnames[i]
value = None
if i >= argcount - defaultcount:
value = defaults[i - (argcount - defaultcount)]
parameter_defaults[name] = value
return parameter_defaults
> No need for the string parameters.
>
> Tim
That's it!
I saw the func_defaults, but could not see how to
make them match up with the co_varnames. I forgot
that keyword args must follow the positional args (duh).
I think this is going to work perfectly.
Thanks to all for the suggestions!
Back to comp.lang.python | Previous | Next | Find similar | Unroll thread
RE: parsing function parameters Lee Harr <missive@hotmail.com> - 2011-08-03 22:30 +0430
csiph-web