Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #10819 > unrolled thread
| Started by | Lee Harr <missive@hotmail.com> |
|---|---|
| First post | 2011-08-03 22:30 +0430 |
| Last post | 2011-08-03 22:30 +0430 |
| Articles | 1 — 1 participant |
Back to article view | Back to comp.lang.python
This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by
below is the oldest one visible, not the original post.
RE: parsing function parameters Lee Harr <missive@hotmail.com> - 2011-08-03 22:30 +0430
| From | Lee Harr <missive@hotmail.com> |
|---|---|
| Date | 2011-08-03 22:30 +0430 |
| Subject | RE: parsing function parameters |
| Message-ID | <mailman.1857.1312394477.1164.python-list@python.org> |
>> 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 top | Article view | comp.lang.python
csiph-web