Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #10816 > unrolled thread
| Started by | Peter Otten <__peter__@web.de> |
|---|---|
| First post | 2011-08-03 18:51 +0200 |
| Last post | 2011-08-03 18:51 +0200 |
| 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 Peter Otten <__peter__@web.de> - 2011-08-03 18:51 +0200
| From | Peter Otten <__peter__@web.de> |
|---|---|
| Date | 2011-08-03 18:51 +0200 |
| Subject | Re: parsing function parameters |
| Message-ID | <mailman.1853.1312390301.1164.python-list@python.org> |
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=42"
>>> def f(a, b, x=1, y=2, z=3):
... pass
...
>>> args, kw = eval("get_args(%s)" % argstr)
>>> inspect.getcallargs(f, *args, **kw)
{'a': 1, 'x': 1, 'b': 2, 'z': 42, 'y': 2}
Back to top | Article view | comp.lang.python
csiph-web