Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #10816
| From | Peter Otten <__peter__@web.de> |
|---|---|
| Subject | Re: parsing function parameters |
| Date | 2011-08-03 18:51 +0200 |
| Organization | None |
| References | <SNT106-W25A79F03CB12FDF1A4230CB13A0@phx.gbl> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.1853.1312390301.1164.python-list@python.org> (permalink) |
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 comp.lang.python | Previous | Next | Find similar | Unroll thread
Re: parsing function parameters Peter Otten <__peter__@web.de> - 2011-08-03 18:51 +0200
csiph-web